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)); } }