Exemplo n.º 1
0
        public TCPSocket(ILogProvider logger)
        {
            // check the interfaces
            LogProvider = logger ?? new DefaultLogProvider(LogLevel.Verbose);
            // use a default message prefix
            if (MessagePrefixLength <= 0)
            {
                MessagePrefixLength = 4;
            }

            _socket = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);
            _socket.SetSocketOption(SocketOptionLevel.Socket, SocketOptionName.ReuseAddress, AllowAddressReuse ? 1 : 0);
            _socket.NoDelay = !UseNaglesAlgorithm;

            for (Int32 i = 0; i < 400; i++)
            {
                _buffers.Insert(new byte[512]);
                _saeas.Insert(new SocketAsyncEventArgs());
            }
        }