// Called on Libuv thread public virtual void OnSocketClosed() { if (_filteredStreamAdapter != null) { _filteredStreamAdapter.Abort(); _rawSocketInput.IncomingFin(); _readInputTask.ContinueWith((task, state) => { ((Connection)state)._filterContext.Connection.Dispose(); ((Connection)state)._filteredStreamAdapter.Dispose(); ((Connection)state)._rawSocketInput.Dispose(); }, this); } else { _rawSocketInput.Dispose(); } lock (_stateLock) { _connectionState = ConnectionState.SocketClosed; if (_socketClosedTcs != null) { // This is always waited on synchronously, so it's safe to // call on the libuv thread. _socketClosedTcs.TrySetResult(null); } } }