From 17da6f3bc530d2108349c8e2794c9bc217fbea19 Mon Sep 17 00:00:00 2001 From: Lachlan Keown Date: Fri, 24 Nov 2017 09:16:46 +1300 Subject: [PATCH] Move BeginAcceptTcpClient() to top of AcceptTcpClientCallback() to prevent exceptions stopping listen loop --- NHttp/HttpServer.cs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/NHttp/HttpServer.cs b/NHttp/HttpServer.cs index b9fdd7b..20b6c99 100644 --- a/NHttp/HttpServer.cs +++ b/NHttp/HttpServer.cs @@ -249,6 +249,8 @@ private void AcceptTcpClientCallback(IAsyncResult asyncResult) { try { + BeginAcceptTcpClient(); // Do this first so as exception below doesn't interrupt listening + var listener = _listener; // Prevent race condition. if (listener == null) @@ -268,9 +270,7 @@ private void AcceptTcpClientCallback(IAsyncResult asyncResult) RegisterClient(client); - client.BeginRequest(); - - BeginAcceptTcpClient(); + client.BeginRequest(); } catch (ObjectDisposedException) {