private static void recycleReadArgs(SocketAsyncEventArgs e, ReadUserToken userToken) { userToken.Reset(); e.SetBuffer(null, 0, 0); if (!readArgPool.PutValue(e)) { e.Dispose(); } }
private static int ReadCompleted(SocketAsyncEventArgs e, ReadUserToken userToken, SocketStream2 sw, out Exception exception) { int bytesTransferred = e.BytesTransferred; SocketError socketError = e.SocketError; recycleReadArgs(e, userToken); if (socketError == SocketError.Success) { sw.OnAsyncReadCompleted(bytesTransferred); if (bytesTransferred == 0) { Logging.debug($"{sw}: remote shutdown"); sw.State |= MyStreamState.RemoteShutdown; } exception = null; return(bytesTransferred); } else { exception = new SocketException((int)socketError); return(-1); } }