private void OnRead(UvStreamHandle handle, int status) { if (status == 0) { // A zero status does not indicate an error or connection end. It indicates // there is no data to be read right now. // See the note at http://docs.libuv.org/en/v1.x/stream.html#c.uv_read_cb. // We need to clean up whatever was allocated by OnAlloc. SocketInput.IncomingDeferred(); return; } var normalRead = status > 0; var normalDone = status == Constants.EOF; var errorDone = !(normalDone || normalRead); var readCount = normalRead ? status : 0; if (normalRead) { Log.ConnectionRead(ConnectionId, readCount); } else { _socket.ReadStop(); if (normalDone) { Log.ConnectionReadFin(ConnectionId); } } IOException error = null; if (errorDone) { Exception uvError; handle.Libuv.Check(status, out uvError); // Log connection resets at a lower (Debug) level. if (status == Constants.ECONNRESET) { Log.ConnectionReset(ConnectionId); } else { Log.ConnectionError(ConnectionId, uvError); } error = new IOException(uvError.Message, uvError); } SocketInput.IncomingComplete(readCount, error); if (errorDone) { Abort(error); } }
void IConnectionControl.Resume() { if (_socket.IsClosed) { return; } Log.ConnectionResume(ConnectionId); try { _socket.ReadStart(_allocCallback, _readCallback, this); } catch (UvException) { // ReadStart() can throw a UvException in some cases (e.g. socket is no longer connected). // This should be treated the same as OnRead() seeing a "normalDone" condition. Log.ConnectionReadFin(ConnectionId); SocketInput.IncomingComplete(0, null); } }