Esempio n. 1
0
        /// <summary>
        /// Tear down the server and dispose of background workers.
        /// Do not use the object after disposal.
        /// </summary>
        /// <param name="disposing">Indicate if resources should be disposed.</param>
        protected virtual void Dispose(bool disposing)
        {
            if (disposing)
            {
                Events.HandleServerDisposing(this, EventArgs.Empty);

                if (_TcpServer != null)
                {
                    if (_TcpServer.IsListening)
                    {
                        Stop();
                    }

                    _TcpServer.Dispose();
                    _TcpServer = null;
                }

                if (_TokenSource != null && !_Token.IsCancellationRequested)
                {
                    _TokenSource.Cancel();
                }

                _Statistics = null;
                _Settings   = null;
                _Routes     = null;
                _Events     = null;
            }
        }
Esempio n. 2
0
        internal HttpContext(
            string ipPort,
            Stream stream,
            string requestHeader,
            WebserverEvents events,
            WebserverSettings.HeaderSettings headers,
            int streamBufferSize)
        {
            if (String.IsNullOrEmpty(requestHeader))
            {
                throw new ArgumentNullException(nameof(requestHeader));
            }
            if (stream == null)
            {
                throw new ArgumentNullException(nameof(stream));
            }
            if (headers == null)
            {
                throw new ArgumentNullException(nameof(headers));
            }
            if (streamBufferSize < 1)
            {
                throw new ArgumentOutOfRangeException(nameof(streamBufferSize));
            }

            Request  = new HttpRequest(ipPort, stream, requestHeader);
            Response = new HttpResponse(ipPort, headers, stream, Request, events, streamBufferSize);
        }
Esempio n. 3
0
        internal HttpResponse(
            string ipPort,
            WebserverSettings.HeaderSettings headers,
            Stream stream,
            HttpRequest req,
            WebserverEvents events,
            int bufferSize)
        {
            if (String.IsNullOrEmpty(ipPort))
            {
                throw new ArgumentNullException(nameof(ipPort));
            }
            if (headers == null)
            {
                throw new ArgumentNullException(nameof(headers));
            }
            if (req == null)
            {
                throw new ArgumentNullException(nameof(req));
            }
            if (stream == null)
            {
                throw new ArgumentNullException(nameof(stream));
            }
            if (events == null)
            {
                throw new ArgumentNullException(nameof(events));
            }

            ProtocolVersion = req.ProtocolVersion;

            _IpPort           = ipPort;
            _HeaderSettings   = headers;
            _Request          = req;
            _Stream           = stream;
            _Events           = events;
            _StreamBufferSize = bufferSize;
        }