예제 #1
0
        /// <summary>
        /// Creates the <see cref="CreateConnectionSocket"/> using the specified options and connects the socket.
        /// Assigns <see cref="LocalEndPoint"/> and <see cref="RemoteEndPoint"/>
        /// </summary>
        /// <param name="addressFamily"></param>
        /// <param name="socketType"></param>
        /// <param name="protocolType"></param>
        /// <param name="addressList"></param>
        /// <param name="port"></param>
        public virtual void Connect(System.Net.Sockets.AddressFamily addressFamily, System.Net.Sockets.SocketType socketType, System.Net.Sockets.ProtocolType protocolType, System.Net.IPAddress[] addressList, int port)
        {
            try
            {
                //Create the socket
                CreateConnectionSocket(addressFamily, socketType, protocolType);

                //Sample the clock
                LasRemoteConnectionStartedDateTime = System.DateTime.UtcNow;

                //Connect the socket
                ConnectionSocket.Connect(addressList, port);

                //Sample the clock
                LastRemoteConnectionCompletedDateTime = System.DateTime.UtcNow;
            }
            finally
            {
                //Assign the NetworkInterface
                NetworkInterface = Common.Extensions.NetworkInterface.NetworkInterfaceExtensions.GetNetworkInterface(ConnectionSocket);

                //Assign the LocalEndPoint
                LocalEndPoint = (System.Net.IPEndPoint)ConnectionSocket.LocalEndPoint;

                //Assign the RemoteEndPoint
                RemoteEndPoint = (System.Net.IPEndPoint)ConnectionSocket.RemoteEndPoint;

                //Call Connect to FlagConnected and call base logic.
                Connect();
            }
        }
예제 #2
0
 public static System.Net.Sockets.Socket ReservePort(System.Net.Sockets.SocketType socketType, System.Net.Sockets.ProtocolType protocol, System.Net.IPAddress localIp, int port)
 {
     System.Net.Sockets.Socket result = new System.Net.Sockets.Socket(localIp.AddressFamily, socketType, protocol);
     result.SetSocketOption(System.Net.Sockets.SocketOptionLevel.Socket, System.Net.Sockets.SocketOptionName.ReuseAddress, true);
     result.Bind(new System.Net.IPEndPoint(localIp, port));
     return(result);
 }
예제 #3
0
        public void PushSystemNetSocketsSocketType(RealStatePtr L, System.Net.Sockets.SocketType val)
        {
            if (SystemNetSocketsSocketType_TypeID == -1)
            {
                bool is_first;
                SystemNetSocketsSocketType_TypeID = getTypeId(L, typeof(System.Net.Sockets.SocketType), out is_first);

                if (SystemNetSocketsSocketType_EnumRef == -1)
                {
                    Utils.LoadCSTable(L, typeof(System.Net.Sockets.SocketType));
                    SystemNetSocketsSocketType_EnumRef = LuaAPI.luaL_ref(L, LuaIndexes.LUA_REGISTRYINDEX);
                }
            }

            if (LuaAPI.xlua_tryget_cachedud(L, (int)val, SystemNetSocketsSocketType_EnumRef) == 1)
            {
                return;
            }

            IntPtr buff = LuaAPI.xlua_pushstruct(L, 4, SystemNetSocketsSocketType_TypeID);

            if (!CopyByValue.Pack(buff, 0, (int)val))
            {
                throw new Exception("pack fail fail for System.Net.Sockets.SocketType ,value=" + val);
            }

            LuaAPI.lua_getref(L, SystemNetSocketsSocketType_EnumRef);
            LuaAPI.lua_pushvalue(L, -2);
            LuaAPI.xlua_rawseti(L, -2, (int)val);
            LuaAPI.lua_pop(L, 1);
        }
예제 #4
0
        public static System.Net.Sockets.Socket ReservePort(System.Net.Sockets.SocketType socketType, System.Net.Sockets.ProtocolType protocol, System.Net.IPAddress localIp, int port)
        {
            System.Net.Sockets.Socket result = new System.Net.Sockets.Socket(localIp.AddressFamily, socketType, protocol);

            Media.Common.Extensions.Socket.SocketExtensions.EnableAddressReuse(result);

            result.Bind(new System.Net.IPEndPoint(localIp, port));

            return(result);
        }
예제 #5
0
        public StandardSocket(System.Net.Sockets.AddressFamily addressFamily,
                              System.Net.Sockets.SocketType socketType,
                              System.Net.Sockets.ProtocolType protocolType,
                              System.Net.EndPoint localEndPoint)
        {
            if (localEndPoint == null)
            {
                throw new ArgumentNullException("localEndPoint");
            }

            socket             = new System.Net.Sockets.Socket(addressFamily, socketType, protocolType);
            this.localEndPoint = localEndPoint;
        }
예제 #6
0
        static StackObject *Ctor_0(ILIntepreter __intp, StackObject *__esp, IList <object> __mStack, CLRMethod __method, bool isNewObj)
        {
            ILRuntime.Runtime.Enviorment.AppDomain __domain = __intp.AppDomain;
            StackObject *ptr_of_this_method;
            StackObject *__ret = ILIntepreter.Minus(__esp, 3);

            ptr_of_this_method = ILIntepreter.Minus(__esp, 1);
            System.Net.Sockets.ProtocolType proto = (System.Net.Sockets.ProtocolType) typeof(System.Net.Sockets.ProtocolType).CheckCLRTypes(StackObject.ToObject(ptr_of_this_method, __domain, __mStack));
            __intp.Free(ptr_of_this_method);
            ptr_of_this_method = ILIntepreter.Minus(__esp, 2);
            System.Net.Sockets.SocketType type = (System.Net.Sockets.SocketType) typeof(System.Net.Sockets.SocketType).CheckCLRTypes(StackObject.ToObject(ptr_of_this_method, __domain, __mStack));
            __intp.Free(ptr_of_this_method);
            ptr_of_this_method = ILIntepreter.Minus(__esp, 3);
            System.Net.Sockets.AddressFamily family = (System.Net.Sockets.AddressFamily) typeof(System.Net.Sockets.AddressFamily).CheckCLRTypes(StackObject.ToObject(ptr_of_this_method, __domain, __mStack));
            __intp.Free(ptr_of_this_method);

            var result_of_this_method = new System.Net.Sockets.Socket(family, type, proto);

            return(ILIntepreter.PushObject(__ret, __mStack, result_of_this_method));
        }
예제 #7
0
        public void UpdateSystemNetSocketsSocketType(RealStatePtr L, int index, System.Net.Sockets.SocketType val)
        {
            if (LuaAPI.lua_type(L, index) == LuaTypes.LUA_TUSERDATA)
            {
                if (LuaAPI.xlua_gettypeid(L, index) != SystemNetSocketsSocketType_TypeID)
                {
                    throw new Exception("invalid userdata for System.Net.Sockets.SocketType");
                }

                IntPtr buff = LuaAPI.lua_touserdata(L, index);
                if (!CopyByValue.Pack(buff, 0, (int)val))
                {
                    throw new Exception("pack fail for System.Net.Sockets.SocketType ,value=" + val);
                }
            }

            else
            {
                throw new Exception("try to update a data with lua type:" + LuaAPI.lua_type(L, index));
            }
        }
예제 #8
0
        public CSADDR_INFO(BluetoothAddress local, BluetoothAddress remote, System.Net.Sockets.SocketType type, System.Net.Sockets.ProtocolType protocol)
        {
            //ensure zeros
            localAddr  = IntPtr.Zero;
            localSize  = 0;
            remoteAddr = IntPtr.Zero;
            remoteSize = 0;

            iSocketType = type;
            iProtocol   = protocol;


            if (local != null)
            {
#if V1
                //have to use AllocHGlobal substitute
                localAddr = Marshal32.AllocHGlobal(40);
                Marshal.Copy(local.ToByteArray(), 0, new IntPtr(localAddr.ToInt32() + 8), 6);
#else
                localAddr = Marshal.AllocHGlobal(40);
                Marshal.WriteInt64(localAddr, 8, local.ToInt64());
#endif
                Marshal.WriteInt16(localAddr, 0, 32);
                localSize = 40;
            }
            if (remote != null)
            {
#if V1
                remoteAddr = Marshal32.AllocHGlobal(40);
                Marshal.Copy(remote.ToByteArray(), 0, new IntPtr(remoteAddr.ToInt32() + 8), 6);
#else
                remoteAddr = Marshal.AllocHGlobal(40);
                Marshal.WriteInt64(remoteAddr, 8, remote.ToInt64());
#endif
                remoteSize = 40;
                Marshal.WriteInt16(remoteAddr, 0, 32);
            }
        }
예제 #9
0
        public static FileDescriptor socket0(bool preferIPv6, bool stream, bool reuse)
        {
#if FIRST_PASS
            return(null);
#else
            try
            {
                System.Net.Sockets.AddressFamily addressFamily = preferIPv6
                                        ? System.Net.Sockets.AddressFamily.InterNetworkV6
                                        : System.Net.Sockets.AddressFamily.InterNetwork;
                System.Net.Sockets.SocketType socketType = stream
                                        ? System.Net.Sockets.SocketType.Stream
                                        : System.Net.Sockets.SocketType.Dgram;
                System.Net.Sockets.ProtocolType protocolType = stream
                                        ? System.Net.Sockets.ProtocolType.Tcp
                                        : System.Net.Sockets.ProtocolType.Udp;
                System.Net.Sockets.Socket socket = new System.Net.Sockets.Socket(addressFamily, socketType, protocolType);
                if (preferIPv6)
                {
                    // enable IPv4 over IPv6 sockets (note that we don't have to check for >= Vista here, because nio sockets only support IPv6 on >= Vista)
                    const System.Net.Sockets.SocketOptionName IPV6_V6ONLY = (System.Net.Sockets.SocketOptionName) 27;
                    socket.SetSocketOption(System.Net.Sockets.SocketOptionLevel.IPv6, IPV6_V6ONLY, 0);
                }
                if (!stream)
                {
                    setConnectionReset(socket, false);
                }
                FileDescriptor fd = new FileDescriptor();
                fd.setSocket(socket);
                return(fd);
            }
            catch (System.Net.Sockets.SocketException x)
            {
                throw global::java.net.SocketUtil.convertSocketExceptionToIOException(x);
            }
#endif
        }
        public static bool _ctor_System_Net_Sockets_Socket_System_Net_Sockets_AddressFamily_System_Net_Sockets_SocketType_System_Net_Sockets_ProtocolType( )
        {
            //Parameters
            System.Net.Sockets.AddressFamily addressFamily = null;
            System.Net.Sockets.SocketType    socketType    = null;
            System.Net.Sockets.ProtocolType  protocolType  = null;


            //Exception
            Exception exception_Real        = null;
            Exception exception_Intercepted = null;

            InterceptionMaintenance.disableInterception( );

            try
            {
                returnValue_Real = System.Net.Sockets.Socket.ctor(addressFamily, socketType, protocolType);
            }

            catch (Exception e)
            {
                exception_Real = e;
            }


            InterceptionMaintenance.enableInterception( );

            try
            {
                returnValue_Intercepted = System.Net.Sockets.Socket.ctor(addressFamily, socketType, protocolType);
            }

            catch (Exception e)
            {
                exception_Intercepted = e;
            }
        }
예제 #11
0
        public void Get(RealStatePtr L, int index, out System.Net.Sockets.SocketType val)
        {
            LuaTypes type = LuaAPI.lua_type(L, index);

            if (type == LuaTypes.LUA_TUSERDATA)
            {
                if (LuaAPI.xlua_gettypeid(L, index) != SystemNetSocketsSocketType_TypeID)
                {
                    throw new Exception("invalid userdata for System.Net.Sockets.SocketType");
                }

                IntPtr buff = LuaAPI.lua_touserdata(L, index);
                int    e;
                if (!CopyByValue.UnPack(buff, 0, out e))
                {
                    throw new Exception("unpack fail for System.Net.Sockets.SocketType");
                }
                val = (System.Net.Sockets.SocketType)e;
            }
            else
            {
                val = (System.Net.Sockets.SocketType)objectCasters.GetCaster(typeof(System.Net.Sockets.SocketType))(L, index, null);
            }
        }
 private Socket(SafeCloseSocket fd)
 {
     this.willBlock = true;
     this.willBlockInternal = true;
     this.m_CloseTimeout = -1;
     s_LoggingEnabled = Logging.On;
     if (s_LoggingEnabled)
     {
         Logging.Enter(Logging.Sockets, this, "Socket", (string) null);
     }
     InitializeSockets();
     if ((fd == null) || fd.IsInvalid)
     {
         throw new ArgumentException(SR.GetString("net_InvalidSocketHandle"));
     }
     this.m_Handle = fd;
     this.addressFamily = System.Net.Sockets.AddressFamily.Unknown;
     this.socketType = System.Net.Sockets.SocketType.Unknown;
     this.protocolType = System.Net.Sockets.ProtocolType.Unknown;
     if (s_LoggingEnabled)
     {
         Logging.Exit(Logging.Sockets, this, "Socket", (string) null);
     }
 }
예제 #13
0
 public Socket(System.Net.Sockets.AddressFamily addressFamily, System.Net.Sockets.SocketType socketType, System.Net.Sockets.ProtocolType protocolType)
 {
 }
예제 #14
0
 public static bool ConnectAsync(System.Net.Sockets.SocketType socketType, System.Net.Sockets.ProtocolType protocolType, System.Net.Sockets.SocketAsyncEventArgs e)
 {
     return(default(bool));
 }
 public unsafe Socket(SocketInformation socketInformation)
 {
     this.willBlock = true;
     this.willBlockInternal = true;
     this.m_CloseTimeout = -1;
     s_LoggingEnabled = Logging.On;
     if (s_LoggingEnabled)
     {
         Logging.Enter(Logging.Sockets, this, "Socket", this.addressFamily);
     }
     ExceptionHelper.UnrestrictedSocketPermission.Demand();
     InitializeSockets();
     if ((socketInformation.ProtocolInformation == null) || (socketInformation.ProtocolInformation.Length < protocolInformationSize))
     {
         throw new ArgumentException(SR.GetString("net_sockets_invalid_socketinformation"), "socketInformation.ProtocolInformation");
     }
     fixed (byte* numRef = socketInformation.ProtocolInformation)
     {
         this.m_Handle = SafeCloseSocket.CreateWSASocket(numRef);
         UnsafeNclNativeMethods.OSSOCK.WSAPROTOCOL_INFO wsaprotocol_info = (UnsafeNclNativeMethods.OSSOCK.WSAPROTOCOL_INFO) Marshal.PtrToStructure((IntPtr) numRef, typeof(UnsafeNclNativeMethods.OSSOCK.WSAPROTOCOL_INFO));
         this.addressFamily = wsaprotocol_info.iAddressFamily;
         this.socketType = (System.Net.Sockets.SocketType) wsaprotocol_info.iSocketType;
         this.protocolType = (System.Net.Sockets.ProtocolType) wsaprotocol_info.iProtocol;
     }
     if (this.m_Handle.IsInvalid)
     {
         SocketException exception = new SocketException();
         if (exception.ErrorCode == 0x2726)
         {
             throw new ArgumentException(SR.GetString("net_sockets_invalid_socketinformation"), "socketInformation");
         }
         throw exception;
     }
     if ((this.addressFamily != System.Net.Sockets.AddressFamily.InterNetwork) && (this.addressFamily != System.Net.Sockets.AddressFamily.InterNetworkV6))
     {
         throw new NotSupportedException(SR.GetString("net_invalidversion"));
     }
     this.m_IsConnected = socketInformation.IsConnected;
     this.willBlock = !socketInformation.IsNonBlocking;
     this.InternalSetBlocking(this.willBlock);
     this.isListening = socketInformation.IsListening;
     this.UseOnlyOverlappedIO = socketInformation.UseOnlyOverlappedIO;
     if (socketInformation.RemoteEndPoint != null)
     {
         this.m_RightEndPoint = socketInformation.RemoteEndPoint;
         this.m_RemoteEndPoint = socketInformation.RemoteEndPoint;
     }
     else
     {
         SocketError notSocket;
         EndPoint any = null;
         if (this.addressFamily == System.Net.Sockets.AddressFamily.InterNetwork)
         {
             any = IPEndPoint.Any;
         }
         else if (this.addressFamily == System.Net.Sockets.AddressFamily.InterNetworkV6)
         {
             any = IPEndPoint.IPv6Any;
         }
         SocketAddress socketAddress = any.Serialize();
         try
         {
             notSocket = UnsafeNclNativeMethods.OSSOCK.getsockname(this.m_Handle, socketAddress.m_Buffer, ref socketAddress.m_Size);
         }
         catch (ObjectDisposedException)
         {
             notSocket = SocketError.NotSocket;
         }
         if (notSocket == SocketError.Success)
         {
             try
             {
                 this.m_RightEndPoint = any.Create(socketAddress);
             }
             catch
             {
             }
         }
     }
     if (s_LoggingEnabled)
     {
         Logging.Exit(Logging.Sockets, this, "Socket", (string) null);
     }
 }
 protected virtual System.Net.Sockets.Socket CreateSocket(System.Net.Sockets.AddressFamily addressFamily, System.Net.Sockets.SocketType socketType, System.Net.Sockets.ProtocolType protocolType, System.Net.EndPoint?endPoint, System.Net.Connections.IConnectionProperties?options)
 {
     throw null;
 }
 public SocketsConnectionFactory(System.Net.Sockets.SocketType socketType, System.Net.Sockets.ProtocolType protocolType)
 {
 }
 public SocketsConnectionFactory(System.Net.Sockets.AddressFamily addressFamily, System.Net.Sockets.SocketType socketType, System.Net.Sockets.ProtocolType protocolType)
 {
 }
예제 #19
0
파일: WlnSocket.cs 프로젝트: fkdl/xcore
 /// <summary>
 ///
 /// </summary>
 /// <param name="addressFamily"></param>
 /// <param name="socketType"></param>
 /// <param name="protocolType"></param>
 public WlnSocket(System.Net.Sockets.AddressFamily addressFamily, System.Net.Sockets.SocketType socketType, System.Net.Sockets.ProtocolType protocolType)
     : base(addressFamily, socketType, protocolType)
 {
 }
예제 #20
0
        public virtual void CreateConnectionSocket(System.Net.Sockets.AddressFamily addressFamily, System.Net.Sockets.SocketType socketType, System.Net.Sockets.ProtocolType protocolType)
        {
            if (ConnectionSocket == null)
            {
                ConnectionSocket = new System.Net.Sockets.Socket(addressFamily, socketType, protocolType);

                if (ConfigureSocket != null)
                {
                    ConfigureSocket(ConnectionSocket);
                }

                CreateWaitHandle(ConnectionSocket.Handle, true);
            }
        }
예제 #21
0
 public override void Create(System.Net.Sockets.AddressFamily af, System.Net.Sockets.SocketType type, System.Net.Sockets.ProtocolType proto)
 {
     throw new System.NotImplementedException();
 }
예제 #22
0
 public Socket(System.Net.Sockets.SocketType socketType, System.Net.Sockets.ProtocolType protocolType)
 {
 }
예제 #23
0
 public static bool ConnectAsync(System.Net.Sockets.SocketType socketType, System.Net.Sockets.ProtocolType protocolType, System.Net.Sockets.SocketAsyncEventArgs e)
 {
     throw null;
 }
 public Socket(System.Net.Sockets.AddressFamily addressFamily, System.Net.Sockets.SocketType socketType, System.Net.Sockets.ProtocolType protocolType)
 {
     this.willBlock = true;
     this.willBlockInternal = true;
     this.m_CloseTimeout = -1;
     s_LoggingEnabled = Logging.On;
     if (s_LoggingEnabled)
     {
         Logging.Enter(Logging.Sockets, this, "Socket", addressFamily);
     }
     InitializeSockets();
     this.m_Handle = SafeCloseSocket.CreateWSASocket(addressFamily, socketType, protocolType);
     if (this.m_Handle.IsInvalid)
     {
         throw new SocketException();
     }
     this.addressFamily = addressFamily;
     this.socketType = socketType;
     this.protocolType = protocolType;
     IPProtectionLevel iPProtectionLevel = SettingsSectionInternal.Section.IPProtectionLevel;
     if (iPProtectionLevel != IPProtectionLevel.Unspecified)
     {
         this.SetIPProtectionLevel(iPProtectionLevel);
     }
     if (s_LoggingEnabled)
     {
         Logging.Exit(Logging.Sockets, this, "Socket", (string) null);
     }
 }