/// <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 the socket and sends the response if it was not done earlier /// and the socket is present. /// </summary> void IDisposable.Dispose() { if (!m_IsResponseClosed) { try { // Iterates over list of client connections and remove its stream from it. m_Listener.RemoveClientStream(m_clientStream); m_clientStream.Flush(); // If KeepAlive is true, if (m_KeepAlive) { // Then socket is tramsferred to the list of waiting for new data. m_Listener.AddToWaitingConnections(m_clientStream); } else // If not KeepAlive then close { m_clientStream.Dispose(); } } catch { } m_IsResponseClosed = true; } GC.SuppressFinalize(this); }
/// <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 { } }
/// <summary> /// Waits for new data from the client. /// </summary> private void WaitingConnectionThreadFunc(OutputNetworkStreamWrapper outputStream) { try { // This is a blocking call waiting for more data. outputStream.m_Socket.Poll(DefaultKeepAliveMilliseconds * 1000, SelectMode.SelectRead); if (outputStream.m_Socket.Available > 0) { // Add this connected stream to the list. lock (this.m_InputStreamsQueue) { this.m_InputStreamsQueue.Enqueue(outputStream); } // Set event that client stream or exception is added to the queue. this.m_RequestArrived.Set(); } else // If no data available - means connection was close on other side or timed out. { outputStream.Dispose(); } } catch { } }
/// <summary> /// Waits for new data from the client. /// </summary> private void WaitingConnectionThreadFunc(OutputNetworkStreamWrapper outputStream) { try { // This is a blocking call waiting for more data. outputStream.m_Socket.Poll(DefaultKeepAliveMilliseconds * 1000, SelectMode.SelectRead); if (outputStream.m_Socket.Available > 0) { // Add this connected stream to the list. lock (m_InputStreamsQueue) { m_InputStreamsQueue.Enqueue(outputStream); } // Set event that client stream or exception is added to the queue. m_RequestArrived.Set(); } else // If no data available - means connection was close on other side or timed out. { outputStream.Dispose(); } } catch { } }