Beispiel #1
0
        /// <summary>
        /// 构造函数,应该是内部的。由内部机制创建
        /// </summary>
        /// <param name="socket">用户对应的 Socket</param>
        /// <param name="sendArgs">创建出来的发送用的SocketAsyncEventArgs(将来可以放到池里)</param>
        /// <param name="receiveArgs">创建出来的接收用的SocketAsyncEventArgs(将来可以放到池里)</param>
        /// <param name="receiveBufferSize">数据接收缓存大小</param>
        internal Token(Socket socket, SocketAsyncEventArgs sendArgs, SocketAsyncEventArgs receiveArgs, int receiveBufferSize)
        {
            this._tokenScket = socket;
            this.SendArgs    = sendArgs;
            this.ReceiveArgs = receiveArgs;

            ReceiveBuffer = new byte[receiveBufferSize];

            _sendQueue          = new BytesQueue(int.MaxValue, MAX_BYTES_SIZE, 256);
            _receiveQueue       = new BytesQueue(int.MaxValue, MAX_BYTES_SIZE, 256);
            _reserveQueuePacked = new BytesQueue(int.MaxValue, MAX_BYTES_SIZE, 256);

            LastMsgReceTickTime = DateTime.Now.Ticks;
            LastMsgSendTickTime = DateTime.Now.Ticks;

            //设置一下timeout
            socket.SendTimeout    = 8 * 1000;//最长发送8秒超时
            socket.ReceiveTimeout = 0;

            userObj = new UserObj();
        }
Beispiel #2
0
 /// <summary>
 /// 现在由于在客户端也添加了一个Token,用于在协议事件的时候方便统一逻辑,当初始化客户端的token的时候调用这个构造方法
 /// </summary>
 internal Token()
 {
     userObj = new UserObj();
 }