Exemple #1
0
        public TcpConnect(TcpServer server, SocketAsyncEventArgs acceptEventArgs)
        {
            HashCode    = Guid.NewGuid();
            this.server = server;

            server.GetIOArgPool().TryPop(out mIOReceiveEventArgs);
            mIOReceiveEventArgs.AcceptSocket = acceptEventArgs.AcceptSocket;
            var dataToken1 = (AsyncUserToken)mIOReceiveEventArgs.UserToken;

            mIOReceiveEventArgs.SetBuffer(dataToken1.bufferOffset, server.socketSettings.BufferSize);
            dataToken1.tcpConn = this;

            server.GetIOArgPool().TryPop(out mIOSendEventArgs);
            mIOSendEventArgs.AcceptSocket = acceptEventArgs.AcceptSocket;
            var dataToken2 = (AsyncUserToken)mIOSendEventArgs.UserToken;

            mIOSendEventArgs.SetBuffer(dataToken2.bufferOffset, server.socketSettings.BufferSize);
            dataToken2.tcpConn = this;

            mSendQueue = new ThreadSafeQueue <byte[]>();

            mState = NetState.Invalid;
        }