Don't register async notifications for MSW blocking sockets
Under MSW calling UnblockAndRegisterWithEventLoop() for blocking sockets
is not only useless, but actually harmful when the socket is used from a
worker thread (which is the common case for blocking sockets), as it
means that the main thread will be receiving notifications for the
socket events and modifying the socket object while it's being used from
the other thread, resulting in data races and general brokenness.
This is similar to e18c8fd29a
for Unix
sockets.
Closes #17937.
This commit is contained in:
@@ -51,9 +51,25 @@ private:
|
||||
|
||||
virtual void UnblockAndRegisterWithEventLoop() wxOVERRIDE
|
||||
{
|
||||
// no need to make the socket non-blocking, Install_Callback() will do
|
||||
// it
|
||||
wxSocketManager::Get()->Install_Callback(this);
|
||||
if ( GetSocketFlags() & wxSOCKET_BLOCK )
|
||||
{
|
||||
// Counter-intuitively, we make the socket non-blocking even in
|
||||
// this case as it is necessary e.g. for Read() to return
|
||||
// immediately if there is no data available. However we must not
|
||||
// install a callback for it as blocking sockets don't use any
|
||||
// events and generating them would actually be harmful (and not
|
||||
// just useless) as they would be dispatched by the main thread
|
||||
// while this blocking socket can be used from a worker one, so it
|
||||
// would result in data races and other unpleasantness.
|
||||
unsigned long trueArg = 1;
|
||||
ioctlsocket(m_fd, FIONBIO, &trueArg);
|
||||
}
|
||||
else
|
||||
{
|
||||
// No need to make the socket non-blocking, Install_Callback() will
|
||||
// do it as a side effect of calling WSAAsyncSelect().
|
||||
wxSocketManager::Get()->Install_Callback(this);
|
||||
}
|
||||
}
|
||||
|
||||
int m_msgnumber;
|
||||
|
Reference in New Issue
Block a user