Detect any attempt to use non-blocking socket from worker threads
This doesn't work, as non-blocking sockets implementation requires dispatching events generated by them, which is only possible from the main thread event loop, and it's better to be upfront about it rather than failing mysteriously later.
This commit is contained in:
parent
8d66bfd7ef
commit
8a29f958a1
@ -289,6 +289,12 @@ public:
|
||||
/**
|
||||
Constructor.
|
||||
|
||||
Notice that if the object is created from a worker thread or if it is
|
||||
created from the main thread but the event loop is not running, @a
|
||||
flags parameter @em must include ::wxSOCKET_BLOCK as non-blocking
|
||||
sockets require dispatching events, which can only be done in the main
|
||||
thread.
|
||||
|
||||
@param flags
|
||||
Socket flags (See wxSocketBase::SetFlags())
|
||||
*/
|
||||
|
@ -25,7 +25,6 @@
|
||||
#include "wx/socket.h"
|
||||
|
||||
#ifndef WX_PRECOMP
|
||||
#include "wx/app.h"
|
||||
#include "wx/object.h"
|
||||
#include "wx/string.h"
|
||||
#include "wx/intl.h"
|
||||
@ -1975,6 +1974,15 @@ bool wxSocketBase::SetLocal(const wxIPV4address& local)
|
||||
wxSocketClient::wxSocketClient(wxSocketFlags flags)
|
||||
: wxSocketBase(flags, wxSOCKET_CLIENT)
|
||||
{
|
||||
// Notice that we don't check for a running event loop here, unlike in
|
||||
// GetBlockingFlagIfNeeded() because it is common to create the sockets
|
||||
// before the event loop is entered and we shouldn't break existing code
|
||||
// doing this as it can still work correctly if it only uses non-blocking
|
||||
// sockets once the event loop is running.
|
||||
wxASSERT_MSG( (flags & wxSOCKET_BLOCK) || wxIsMainThread(),
|
||||
wxS("Non-blocking sockets may only be created ")
|
||||
wxS("in the main thread") );
|
||||
|
||||
m_initialRecvBufferSize =
|
||||
m_initialSendBufferSize = -1;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user