Пример #1
0
 /// <summary>
 ///
 /// </summary>
 public SocketBufferProvider(SocketSetting setting) : this()
 {
     this.setting = setting;
     this.pools   = new List <SocketBuffer[]>();
     this.groups  = new ConcurrentQueue <RangeTuple <int, int> >();
     this.Extend();
 }
Пример #2
0
        /// <summary>
        ///
        /// </summary>
        public ClientSocket(SocketSetting setting, ISocketBufferProvider bufferProvider, EndPoint serverEndPoint, ISocketProtocol socketProtocol = null, EndPoint localEndPoint = null)
        {
            this.serverEndPoint = serverEndPoint;
            this.localEndPoint  = localEndPoint;
            this.bufferProvider = bufferProvider;
            this.socketProtocol = socketProtocol;
            this.eventHandlers  = new List <ResultEventHandler <OnReceivedSocketEventArgs, byte[]> >();
            this.socket         = new System.Net.Sockets.Socket(System.Net.Sockets.AddressFamily.InterNetwork, System.Net.Sockets.SocketType.Stream, System.Net.Sockets.ProtocolType.Tcp)
            {
                ReceiveBufferSize = setting.ReceiveBufferSize,
                SendBufferSize    = setting.SendBufferSize,
                NoDelay           = true,
                Blocking          = false,
            };

            //用来控制开始连接超时检查
            this.manualResetEvent = new System.Threading.ManualResetEvent(false);
        }
Пример #3
0
        /// <summary>
        ///
        /// </summary>
        public ServerSocket(SocketSetting setting, ISocketBufferProvider bufferProvider, EndPoint listeningEndPoint, ISocketProtocol socketProtocol = null)
        {
            this.listeningEndPoint = listeningEndPoint;
            this.bufferProvider    = bufferProvider;
            this.setting           = setting;
            this.socketProtocol    = socketProtocol;
            this.eventHandlers     = new List <ResultEventHandler <OnReceivedSocketEventArgs, byte[]> >();
            this.socket            = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp)
            {
                ReceiveBufferSize = setting.ReceiveBufferSize,
                SendBufferSize    = setting.SendBufferSize,
                NoDelay           = true,
                Blocking          = false,
            };

            this.connections = new ConcurrentDictionary <ulong, Connection>();
            this.acceptSocketAsyncEventArgs            = new SocketAsyncEventArgs();
            this.acceptSocketAsyncEventArgs.Completed += AcceptAsyncCompleted;
        }
Пример #4
0
 /// <summary>
 ///
 /// </summary>
 public ClientSocket(SocketSetting setting, EndPoint serverEndPoint, ISocketProtocol socketProtocol = null, EndPoint localEndPoint = null) : this(setting, new SocketBufferProvider(setting), serverEndPoint, socketProtocol, localEndPoint)
 {
 }
Пример #5
0
 /// <summary>
 ///
 /// </summary>
 public ServerSocket(SocketSetting setting, EndPoint listeningEndPoint, ISocketProtocol socketProtocol = null) : this(setting, new SocketBufferProvider(setting), listeningEndPoint, socketProtocol)
 {
 }