/// <summary>
 /// Closes the stream attached to this listener context.
 /// </summary>
 public void Close(int lingerValue)
 {
     try
     {
         // Close the underlying stream
         if (m_clientOutputStream != null)
         {
             try
             {
                 if (m_clientOutputStream.m_Socket != null)
                 {
                     m_clientOutputStream.m_Socket.SetSocketOption(SocketOptionLevel.Socket, SocketOptionName.Linger, lingerValue);
                 }
             }
             catch {}
             m_clientOutputStream.Dispose();
             m_clientOutputStream = null;
         }
         if (m_clientInputStream != null)
         {
             m_clientInputStream.Dispose();
             m_clientInputStream = null;
         }
     }
     catch
     {
     }
 }
        /// <summary>
        /// Closes a response stream, if present.
        /// </summary>
        /// <param name="disposing">Not used.</param>
        protected override void Dispose(bool disposing)
        {
            if (m_responseStream != null)
            {
                bool closeConnection = true;
                if (m_httpWebRequest.KeepAlive)
                {
                    string connValue = null;

                    // Check if server have sent use "Connection:Close"
                    if (m_httpResponseHeaders != null)
                    {
                        connValue = m_httpResponseHeaders[HttpKnownHeaderNames.Connection];
                    }

                    // If server had not send this header or value is not "close", then we keep connection.
                    closeConnection = connValue == null || connValue.ToLower() == HttpKnownHeaderValues.close;

                    // Add new socket and port used to connect to the list of sockets.
                    // Save connected socket and Destination IP End Point, so it can be used next time.
                    // But first we need to validate that this socket is already not in the list. We do not want same socket to be twice in the list.
                    lock (HttpWebRequest.m_ConnectedStreams)
                    {
                        // If it is not in the list - Add it
                        if (closeConnection)
                        {
                            if (HttpWebRequest.m_ConnectedStreams.Contains(m_responseStream))
                            {
                                // Either KeepAlive was not set or server requested closing connection.
                                HttpWebRequest.m_ConnectedStreams.Remove(m_responseStream);
                            }

                            // Closing connection socket.
                            m_responseStream.Dispose();
                        }
                        else
                        {
                            m_responseStream.ReleaseStream();
                        }
                    }
                }

                // Set flag that we already completed work on this stream.
                m_responseStream = null;
            }
        }
 /// <summary>
 /// Closes the stream attached to this listener context.
 /// </summary>
 public void Close()
 {
     try
     {
         // Close the underlying stream
         if (m_clientOutputStream != null)
         {
             m_clientOutputStream.HeadersDelegate = null;
             m_clientOutputStream.Dispose();
         }
         if (m_clientInputStream != null)
         {
             m_clientInputStream.Dispose();
         }
     }
     catch
     {
     }
 }