Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public void ProcessReceive(SocketAsyncEventArgs e)
- {
- // check if the remote host closed the connection
- if (e.BytesTransferred <= 0)
- {
- Close(CloseReason.ClientClosing);
- return;
- }
- if (e.SocketError != SocketError.Success)
- {
- Close(CloseReason.SocketError);
- return;
- }
- int bytesTransferred = e.BytesTransferred;
- int offset = e.Offset;
- while (bytesTransferred > 0)
- {
- TCommandInfo commandInfo = default(TCommandInfo);
- int left = bytesTransferred;
- int offsetAcc = offset;
- while(left > 0)
- {
- commandInfo = FindCommand(e.Buffer, offsetAcc, left, true, out left);
- offsetAcc = offset + (bytesTransferred - left);
- }
- if (IsClosed)
- return;
- if (commandInfo == null)
- break;
- try
- {
- ExecuteCommand(commandInfo);
- }
- catch (Exception exc)
- {
- AppServer.Logger.LogError(this, exc);
- HandleExceptionalError(exc);
- }
- if (left <= 0)
- break;
- bytesTransferred = left;
- offset = e.Offset + e.BytesTransferred - left;
- }
- //read the next block of data sent from the client
- StartReceive(e);
- }
Advertisement
Add Comment
Please, Sign In to add comment