Skip to content
This repository was archived by the owner on Jun 5, 2019. It is now read-only.

Commit 966f756

Browse files
committed
Merge pull request #207 from mortezag/fixHttpListener
Fix HttpListenerContext.Close()
2 parents f423159 + df41d6e commit 966f756

File tree

2 files changed

+28
-13
lines changed

2 files changed

+28
-13
lines changed

Framework/Core/System/HTTP/System.Net.HttpListenerContext.cs

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -150,8 +150,7 @@ public void Close()
150150
public void Close(int lingerValue)
151151
{
152152
try
153-
{
154-
// Close the underlying stream
153+
{
155154
if (m_clientOutputStream != null)
156155
{
157156
try
@@ -162,9 +161,21 @@ public void Close(int lingerValue)
162161
}
163162
}
164163
catch{}
164+
}
165+
166+
if (m_ResponseToClient != null)
167+
{
168+
m_ResponseToClient.Close();
169+
m_ResponseToClient = null;
170+
}
171+
172+
// Close the underlying stream
173+
if (m_clientOutputStream != null)
174+
{
165175
m_clientOutputStream.Dispose();
166176
m_clientOutputStream = null;
167177
}
178+
168179
if (m_clientInputStream != null)
169180
{
170181
m_clientInputStream.Dispose();

Framework/Core/System/HTTP/System.Net.HttpListenerResponse.cs

Lines changed: 15 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -439,20 +439,24 @@ void IDisposable.Dispose()
439439
{
440440
if (!m_IsResponseClosed)
441441
{
442-
// Iterates over list of client connections and remove its stream from it.
443-
m_Listener.RemoveClientStream(m_clientStream);
442+
try
443+
{
444+
// Iterates over list of client connections and remove its stream from it.
445+
m_Listener.RemoveClientStream(m_clientStream);
444446

445-
m_clientStream.Flush();
447+
m_clientStream.Flush();
446448

447-
// If KeepAlive is true,
448-
if (m_KeepAlive)
449-
{ // Then socket is tramsferred to the list of waiting for new data.
450-
m_Listener.AddToWaitingConnections(m_clientStream);
451-
}
452-
else // If not KeepAlive then close
453-
{
454-
m_clientStream.Dispose();
449+
// If KeepAlive is true,
450+
if (m_KeepAlive)
451+
{ // Then socket is tramsferred to the list of waiting for new data.
452+
m_Listener.AddToWaitingConnections(m_clientStream);
453+
}
454+
else // If not KeepAlive then close
455+
{
456+
m_clientStream.Dispose();
457+
}
455458
}
459+
catch{}
456460

457461
m_IsResponseClosed = true;
458462
}

0 commit comments

Comments
 (0)