コード例 #1
0
ファイル: PeaRoxyWeb.cs プロジェクト: orf53975/PeaRoxy
        private void Close(
            string title   = null,
            string message = null,
            ErrorRenderer.HttpHeaderCode code = ErrorRenderer.HttpHeaderCode.C500ServerError,
            bool async = false)
        {
            try
            {
                if (this.ParentClient != null)
                {
                    if (this.isHttps && this.clientSslStream != null)
                    {
                        this.ParentClient.Close(title, message, code, async, this.clientSslStream);
                    }
                    else
                    {
                        this.ParentClient.Close(title, message, code, async);
                    }
                }

                this.IsClosed = true;

                if (async)
                {
                    byte[] db = new byte[0];
                    if (this.UnderlyingSocket != null)
                    {
                        this.UnderlyingSocket.BeginSend(
                            db,
                            0,
                            db.Length,
                            SocketFlags.None,
                            delegate(IAsyncResult ar)
                        {
                            try
                            {
                                this.UnderlyingSocket.Close();         // Close request connection it-self
                                this.UnderlyingSocket.EndSend(ar);
                            }
                            catch (Exception)
                            {
                            }
                        },
                            null);
                    }
                }
                else
                {
                    if (this.UnderlyingSocket != null)
                    {
                        this.UnderlyingSocket.Close();
                    }
                }
            }
            catch
            {
            }
        }
コード例 #2
0
        private void Close(
            string title   = null,
            string message = null,
            ErrorRenderer.HttpHeaderCode code = ErrorRenderer.HttpHeaderCode.C500ServerError,
            bool async = false)
        {
            try
            {
                this.IsClosed = true;
                if (this.Protocol != null)
                {
                    this.Protocol.Close(title, async);
                }

                if (this.ParentClient != null)
                {
                    this.ParentClient.Close(title, message, code, async);
                }
            }
            catch
            {
            }
        }
コード例 #3
0
        /// <summary>
        ///     The close method which supports mentioning a message about the reason
        /// </summary>
        /// <param name="title">
        ///     The title.
        /// </param>
        /// <param name="message">
        ///     The message.
        /// </param>
        /// <param name="code">
        ///     The HTTP code.
        /// </param>
        /// <param name="async">
        ///     Indicating if the closing process should treat the client as an asynchronous client
        /// </param>
        /// <param name="sslstream">
        ///     The SSL stream if any.
        /// </param>
        public void Close(
            string title   = null,
            string message = null,
            ErrorRenderer.HttpHeaderCode code = ErrorRenderer.HttpHeaderCode.C500ServerError,
            bool async          = false,
            SslStream sslstream = null)
        {
            this.Status = StatusCodes.Closing;
            try
            {
                if (title != null)
                {
                    if (message == null)
                    {
                        message = "No more information.";
                    }

                    this.LastError = title + "\r\n" + message;
                }

                if (this.UnderlyingSocket != null)
                {
                    // Testing or not
                    if (this.LastError != string.Empty && title != null)
                    {
                        ProxyController.LogIt(title);
                    }

                    if (title == null ||
                        !this.Controller.ErrorRenderer.RenderError(this, title, message, code, sslstream))
                    {
                        if (async)
                        {
                            byte[] db = new byte[0];
                            if (this.UnderlyingSocket != null)
                            {
                                this.UnderlyingSocket.BeginSend(
                                    db,
                                    0,
                                    db.Length,
                                    SocketFlags.None,
                                    delegate(IAsyncResult ar)
                                {
                                    try
                                    {
                                        this.UnderlyingSocket.Close();         // Close request connection it-self
                                        this.UnderlyingSocket.EndSend(ar);
                                    }
                                    catch (Exception)
                                    {
                                    }
                                },
                                    null);
                            }
                        }
                        else
                        {
                            if (this.UnderlyingSocket != null)
                            {
                                this.UnderlyingSocket.Close();
                            }
                        }
                    }
                }
            }
            catch
            {
            }

            this.IsClosed = true;
            this.Controller.ClientDisconnected(this);
        }