Esempio n. 1
0
        internal void Close(bool forceClose = false)
        {
            if (_sock != null)
            {
                GetResponseStream()?.Dispose();

                _oStream = null;
            }

            if (_sock == null)
            {
                return;
            }

            forceClose = forceClose ||
                         !_context.Request.KeepAlive ||
                         _context.Response.Headers["connection"] == "close";

            if (!forceClose)
            {
                if (_context.HttpListenerRequest.FlushInput())
                {
                    Reuses++;
                    Unbind();
                    Init();
#pragma warning disable 4014
                    BeginReadRequest();
#pragma warning restore 4014
                    return;
                }
            }

            using (var s = _sock)
            {
                _sock = null;
                try
                {
                    s?.Shutdown(SocketShutdown.Both);
                }
                catch
                {
                    // ignored
                }
            }

            Unbind();
            RemoveConnection();
        }
Esempio n. 2
0
 public ResponseStream GetResponseStream() => _oStream ??
 (_oStream =
      new ResponseStream(Stream, _context.HttpListenerResponse, _context.Listener?.IgnoreWriteExceptions ?? true));