示例#1
0
        /// <summary>
        /// Create a new context.
        /// </summary>
        /// <param name="isSecured">true if socket is running HTTPS.</param>
        /// <param name="endPoint">Client that connected</param>
        /// <param name="stream">Network/SSL stream.</param>
        /// <returns>A context.</returns>
        protected HttpClientContext CreateContext(bool isSecured, IPEndPoint endPoint, Stream stream, Socket sock)
        {
            HttpClientContext context;

            lock (_contextQueue)
            {
                if (_contextQueue.Count > 0)
                {
                    context = _contextQueue.Dequeue();
                    if (!context.Available)
                    {
                        context = CreateNewContext(isSecured, endPoint, stream, sock);
                        context.Disconnected    += OnFreeContext;
                        context.RequestReceived += OnRequestReceived;
                        context.EndWhenDone      = true;
                    }
                }
                else
                {
                    context = CreateNewContext(isSecured, endPoint, stream, sock);
                    context.Disconnected    += OnFreeContext;
                    context.RequestReceived += OnRequestReceived;
                }
            }

            context.Stream        = stream;
            context.IsSecured     = isSecured;
            context.RemotePort    = endPoint.Port.ToString();
            context.RemoteAddress = endPoint.Address.ToString();
            _contextTimeoutManager.StartMonitoringContext(context);
            context.Start();

            return(context);
        }
示例#2
0
        /// <summary>
        /// Create a new context.
        /// </summary>
        /// <param name="isSecured">true if socket is running HTTPS.</param>
        /// <param name="endPoint">Client that connected</param>
        /// <param name="stream">Network/SSL stream.</param>
        /// <returns>A context.</returns>
        protected HttpClientContext CreateContext(bool isSecured, IPEndPoint endPoint, Stream stream, Socket sock)
        {
            HttpClientContext context;

            context = CreateNewContext(isSecured, endPoint, stream, sock);
            context.Disconnected    += OnFreeContext;
            context.RequestReceived += OnRequestReceived;

            context.Stream        = stream;
            context.IsSecured     = isSecured;
            context.RemotePort    = endPoint.Port.ToString();
            context.RemoteAddress = endPoint.Address.ToString();
            ContextTimeoutManager.StartMonitoringContext(context);
            m_activeContexts[context.contextID] = context;
            context.Start();
            return(context);
        }