Bugfix: Keep accepting new connections after getting WSAETIMEDOUT on a new connection request

This commit is contained in:
Tal Aloni 2017-08-01 10:53:05 +03:00
parent de256fdb51
commit 13680eefa0

View file

@ -85,7 +85,7 @@ namespace SMBLibrary.Server
m_connectionManager.ReleaseAllConnections(); m_connectionManager.ReleaseAllConnections();
} }
// This method Accepts new connections // This method accepts new connections
private void ConnectRequestCallback(IAsyncResult ar) private void ConnectRequestCallback(IAsyncResult ar)
{ {
Socket listenerSocket = (Socket)ar.AsyncState; Socket listenerSocket = (Socket)ar.AsyncState;
@ -101,11 +101,11 @@ namespace SMBLibrary.Server
} }
catch (SocketException ex) catch (SocketException ex)
{ {
const int WSAECONNRESET = 10054; const int WSAECONNRESET = 10054; // The client may have closed the connection before we start to process the connection request.
// Client may have closed the connection before we start to process the connection request. const int WSAETIMEDOUT = 10060; // The client did not properly respond after a period of time.
// When we get this error, we have to continue to accept other requests. // When we get WSAECONNRESET or WSAETIMEDOUT, we have to continue to accept other connection requests.
// See http://stackoverflow.com/questions/7704417/socket-endaccept-error-10054 // See http://stackoverflow.com/questions/7704417/socket-endaccept-error-10054
if (ex.ErrorCode == WSAECONNRESET) if (ex.ErrorCode == WSAECONNRESET || ex.ErrorCode == WSAETIMEDOUT)
{ {
listenerSocket.BeginAccept(ConnectRequestCallback, listenerSocket); listenerSocket.BeginAccept(ConnectRequestCallback, listenerSocket);
} }