Use closesocket() for closing sockets under MSW
If accepting a socket connection failed, wxSocketImpl::Accept() used close() to close the socket even under MSW, but it can be only used for the file descriptors there and closesocket() must be used instead for the sockets. Add new (private) wxCloseSocket define and use it both here, to fix the bug, and elsewhere to make the code more clear. Closes #18407.
This commit is contained in:
committed by
Vadim Zeitlin
parent
b309868930
commit
a4f2303361
@@ -34,6 +34,8 @@
|
|||||||
#define wxIoctlSocketArg_t u_long
|
#define wxIoctlSocketArg_t u_long
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#define wxCloseSocket closesocket
|
||||||
|
|
||||||
// ----------------------------------------------------------------------------
|
// ----------------------------------------------------------------------------
|
||||||
// MSW-specific socket implementation
|
// MSW-specific socket implementation
|
||||||
// ----------------------------------------------------------------------------
|
// ----------------------------------------------------------------------------
|
||||||
|
@@ -23,6 +23,8 @@
|
|||||||
|
|
||||||
#include "wx/private/fdiomanager.h"
|
#include "wx/private/fdiomanager.h"
|
||||||
|
|
||||||
|
#define wxCloseSocket close
|
||||||
|
|
||||||
class wxSocketImplUnix : public wxSocketImpl,
|
class wxSocketImplUnix : public wxSocketImpl,
|
||||||
public wxFDIOHandler
|
public wxFDIOHandler
|
||||||
{
|
{
|
||||||
@@ -64,7 +66,7 @@ private:
|
|||||||
{
|
{
|
||||||
DisableEvents();
|
DisableEvents();
|
||||||
|
|
||||||
close(m_fd);
|
wxCloseSocket(m_fd);
|
||||||
}
|
}
|
||||||
|
|
||||||
virtual void UnblockAndRegisterWithEventLoop() wxOVERRIDE
|
virtual void UnblockAndRegisterWithEventLoop() wxOVERRIDE
|
||||||
|
@@ -529,7 +529,7 @@ wxSocketImpl *wxSocketImpl::Accept(wxSocketBase& wxsocket)
|
|||||||
WX_SOCKLEN_T fromlen = sizeof(from);
|
WX_SOCKLEN_T fromlen = sizeof(from);
|
||||||
const wxSOCKET_T fd = accept(m_fd, &from.addr, &fromlen);
|
const wxSOCKET_T fd = accept(m_fd, &from.addr, &fromlen);
|
||||||
|
|
||||||
wxScopeGuard closeSocket = wxMakeGuard(wxClose, fd);
|
wxScopeGuard closeSocket = wxMakeGuard(wxCloseSocket, fd);
|
||||||
|
|
||||||
// accepting is similar to reading in the sense that it resets "ready for
|
// accepting is similar to reading in the sense that it resets "ready for
|
||||||
// read" flag on the socket
|
// read" flag on the socket
|
||||||
|
@@ -310,7 +310,7 @@ void wxSocketImplMSW::DoClose()
|
|||||||
{
|
{
|
||||||
wxSocketManager::Get()->Uninstall_Callback(this);
|
wxSocketManager::Get()->Uninstall_Callback(this);
|
||||||
|
|
||||||
closesocket(m_fd);
|
wxCloseSocket(m_fd);
|
||||||
}
|
}
|
||||||
|
|
||||||
wxSocketError wxSocketImplMSW::GetLastError() const
|
wxSocketError wxSocketImplMSW::GetLastError() const
|
||||||
|
Reference in New Issue
Block a user