private void TryDequeueAndPostSend(TNSocket socket, SocketAsyncEventArgs ioEventArgs) { SocketAsyncResult result; if (socket.TryDequeueOrReset(out result)) { DataToken dataToken = (DataToken)ioEventArgs.UserToken; dataToken.Socket = socket; dataToken.AsyncResult = result; dataToken.byteArrayForMessage = result.Data; dataToken.messageLength = result.Data.Length; try { PostSend(ioEventArgs); } catch (Exception ex) { dataToken.ResultCallback(ResultCode.Error, ex); ResetSendFlag(); } } else { //ResetSendFlag(); } }
private void TryDequeueAndPostSend(TNSocket socket, SocketAsyncEventArgs ioEventArgs) { bool isOwner = ioEventArgs == null; SocketAsyncResult result; if (socket.TryDequeueOrReset(out result)) { if (ioEventArgs == null) { ioEventArgs = ioEventArgsPool.Pop(); ioEventArgs.AcceptSocket = socket.WorkSocket; } DataToken dataToken = (DataToken)ioEventArgs.UserToken; dataToken.Socket = socket; dataToken.AsyncResult = result; dataToken.byteArrayForMessage = result.Data; dataToken.messageLength = result.Data.Length; try { PostSend(ioEventArgs); } catch (Exception ex) { dataToken.ResultCallback(ResultCode.Error, ex); if (isOwner) { ReleaseIOEventArgs(ioEventArgs); } socket.ResetSendFlag(); } } else { ReleaseIOEventArgs(ioEventArgs); //socket.ResetSendFlag(); } }