예제 #1
0
        bool HandlePacket(SocketAsyncEventArgs e)
        {
            AsyncUserToken token  = e.UserToken as AsyncUserToken;
            Socket         socket = token.WorkSocket;

            Debug.Assert(socket.ProtocolType == ProtocolType.Tcp);

            token.ReceiveCompleted = e.BytesTransferred < e.Count;
            if (!token.ReceiveCompleted)
            {
                token.AddReceiveBuffer(e);

                SetBuffer(e);
                bool willRaiseEvent = socket.ReceiveAsync(e); //重用e,用于下一个receive
                if (!willRaiseEvent)
                {
                    ProcessReceive(e);
                }

                return(true);
            }
            else //token.ReceiveCompleted
            {
                token.AddReceiveBuffer(e);
                Core.Buffer receiveBuf = token.GetReceiveBuf();
                return(HandleRequest(receiveBuf.Data, receiveBuf.Offset, receiveBuf.Count, e));
            }
        }
예제 #2
0
 public static void SetBuffer(this SocketAsyncEventArgs arg, Core.Buffer buf)
 {
     arg.SetBuffer(buf.Data, buf.Offset, buf.Count);
 }