Skip to content

Commit 6297436

Browse files
add additional http request logging
1 parent a614723 commit 6297436

File tree

3 files changed

+21
-15
lines changed

3 files changed

+21
-15
lines changed

SocketHttpListener/Net/HttpEndPointListener.cs

Lines changed: 21 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -81,8 +81,10 @@ private void CreateSocket()
8181
{
8282
if (_enableDualMode && _endpoint.Address.Equals(IPAddress.IPv6Any) &&
8383
(string.Equals(ex.ErrorCode, "AddressFamilyNotSupported", StringComparison.OrdinalIgnoreCase) ||
84-
// mono on bsd is throwing this
85-
string.Equals(ex.ErrorCode, "ProtocolNotSupported", StringComparison.OrdinalIgnoreCase)))
84+
// mono 4.8.1 and lower on bsd is throwing this
85+
string.Equals(ex.ErrorCode, "ProtocolNotSupported", StringComparison.OrdinalIgnoreCase) ||
86+
// mono 5.2 on bsd is throwing this
87+
string.Equals(ex.ErrorCode, "OperationNotSupported", StringComparison.OrdinalIgnoreCase)))
8688
{
8789
_endpoint = new IPEndPoint(IPAddress.Any, _endpoint.Port);
8890
_enableDualMode = false;
@@ -138,6 +140,18 @@ private static void TryCloseAndDispose(Socket socket)
138140
}
139141
}
140142

143+
private static void TryClose(Socket socket)
144+
{
145+
try
146+
{
147+
socket.Close();
148+
}
149+
catch
150+
{
151+
152+
}
153+
}
154+
141155
private static void Accept(Socket socket, SocketAsyncEventArgs acceptEventArg, ref Socket accepted)
142156
{
143157
// acceptSocket must be cleared since the context object is being reused
@@ -167,17 +181,7 @@ private static void Accept(Socket socket, SocketAsyncEventArgs acceptEventArg, r
167181

168182
if (accepted != null)
169183
{
170-
try
171-
{
172-
#if NET46
173-
accepted.Close();
174-
#else
175-
accepted.Dispose();
176-
#endif
177-
}
178-
catch
179-
{
180-
}
184+
TryClose(accepted);
181185
accepted = null;
182186
}
183187
}
@@ -263,6 +267,8 @@ private async void ProcessAccept(Socket accepted)
263267
return;
264268
}
265269

270+
_logger.Info("HttpEndPointListener.ProcessAccept from {0} secure connection: {1}", accepted.RemoteEndPoint.ToString(), _secure);
271+
266272
HttpConnection conn = new HttpConnection(_logger, accepted, listener, _secure, _cert, _cryptoProvider, _memoryStreamFactory, _textEncoding, _fileSystem, _environment);
267273

268274
await conn.Init().ConfigureAwait(false);
@@ -276,6 +282,8 @@ private async void ProcessAccept(Socket accepted)
276282
}
277283
catch (Exception ex)
278284
{
285+
TryClose(accepted);
286+
279287
_logger.ErrorException("Error in ProcessAccept", ex);
280288
}
281289
}

SocketHttpListener/Net/HttpListener.cs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -248,7 +248,6 @@ void IDisposable.Dispose()
248248

249249
Close(true); //TODO: Should we force here or not?
250250
disposed = true;
251-
GC.SuppressFinalize(this);
252251
}
253252

254253
internal void CheckDisposed()

SocketHttpListener/WebSocket.cs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -879,7 +879,6 @@ public Task SendAsync(string data)
879879
void IDisposable.Dispose()
880880
{
881881
Close(CloseStatusCode.Away, null);
882-
GC.SuppressFinalize(this);
883882
}
884883

885884
#endregion

0 commit comments

Comments
 (0)