Skip to content
Snippets Groups Projects
Commit c86e3aaa authored by Lucas Givord's avatar Lucas Givord
Browse files

vtkSocket: fix win32 error handling

Previously when encountering an error during a Receive() call, server
hangs indefinitely as only WSAENOBUFS was checked.

For WSAECONNABORTED we cannot know if the disconnection is expected or
not so we don't output an error but log a trace for debugging purpose.
parent 8dcd14dc
No related branches found
No related tags found
No related merge requests found
......@@ -2,6 +2,7 @@
// SPDX-License-Identifier: BSD-3-Clause
#include "vtkSocket.h"
#include "vtkLogger.h"
#include "vtkObjectFactory.h"
// The VTK_SOCKET_FAKE_API definition is given to the compiler
......@@ -605,15 +606,27 @@ int vtkSocket::Receive(void* data, int length, int readFully /*=1*/)
}
#if defined(_WIN32) && !defined(__CYGWIN__)
if ((nRecvd == vtkSocketErrorReturnMacro) && (WSAGetLastError() == WSAENOBUFS))
if ((nRecvd == vtkSocketErrorReturnMacro))
{
// On long messages, Windows recv sometimes fails with WSAENOBUFS, but
// will work if you try again.
if ((tries++ < 1000))
int lastError = WSAGetLastError();
if (lastError == WSAECONNABORTED)
{
Sleep(1);
continue;
// From the receiver we cannot know if the connection abort is expected or not, this is why
// we output a trace instead of an error.
vtkLog(TRACE, "Socket error: connection abort.");
return 0;
}
else if (lastError == WSAENOBUFS)
{
// On long messages, Windows recv sometimes fails with WSAENOBUFS, but
// will work if you try again.
if ((tries++ < 1000))
{
Sleep(1);
continue;
}
}
vtkSocketErrorMacro(vtkErrnoMacro, "Socket error in call to recv.");
return 0;
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment