/// <summary> /// Process receieve. /// </summary> /// <param name="e"></param> private void ProcessReceive(SocketAsyncEventArgs e) { if (e.SocketError == SocketError.Success) { if (e.BytesTransferred <= 0 || !(e.UserToken is NetUser user)) { return; } SocketAsyncUtils.ReceiveData(e, user.Token, this.PacketProcessor); if (!user.Socket.ReceiveAsync(e)) { this.ProcessReceive(e); } } else if (e.SocketError == SocketError.ConnectionReset) { this.Disconnect(); } }
/// <summary> /// Process receieve. /// </summary> /// <param name="e"></param> private void ProcessReceive(SocketAsyncEventArgs e) { if (e.SocketError == SocketError.Success && e.BytesTransferred > 0) { if (!(e.UserToken is NetUser connection)) { return; } SocketAsyncUtils.ReceiveData(e, connection.Token, this.PacketProcessor); if (!connection.Socket.ReceiveAsync(e)) { this.ProcessReceive(e); } } else { this.CloseConnection(e); } }