Ejemplo n.º 1
0
        internal void Close(bool forceClose = false)
        {
            if (_sock != null)
            {
                _oStream?.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();
        }
Ejemplo n.º 2
0
        private void Dispose(bool disposing)
        {
            Close(true);

            if (!disposing)
            {
                return;
            }

            _timer?.Dispose();
            _sock?.Dispose();
            _ms?.Dispose();
            _iStream?.Dispose();
            _oStream?.Dispose();
            Stream?.Dispose();
            _lastListener?.Dispose();
            ClientCertificate?.Dispose();
        }