Avoid closing invalid socket after unsuccessful Accept()
Calling wxSocket::Accept() may return an invalid socket, especially when non-blocking, so don't close it unconditionally. This avoids an assertion failure in MSVC CRT due to calling closesocket() with an invalid argument.
This commit is contained in:
@@ -529,8 +529,6 @@ wxSocketImpl *wxSocketImpl::Accept(wxSocketBase& wxsocket)
|
||||
WX_SOCKLEN_T fromlen = sizeof(from);
|
||||
const wxSOCKET_T fd = accept(m_fd, &from.addr, &fromlen);
|
||||
|
||||
wxScopeGuard closeSocket = wxMakeGuard(wxCloseSocket, fd);
|
||||
|
||||
// accepting is similar to reading in the sense that it resets "ready for
|
||||
// read" flag on the socket
|
||||
ReenableEvents(wxSOCKET_INPUT_FLAG);
|
||||
@@ -538,6 +536,8 @@ wxSocketImpl *wxSocketImpl::Accept(wxSocketBase& wxsocket)
|
||||
if ( fd == INVALID_SOCKET )
|
||||
return NULL;
|
||||
|
||||
wxScopeGuard closeSocket = wxMakeGuard(wxCloseSocket, fd);
|
||||
|
||||
wxSocketManager * const manager = wxSocketManager::Get();
|
||||
if ( !manager )
|
||||
return NULL;
|
||||
|
Reference in New Issue
Block a user