diff --git a/interface/wx/socket.h b/interface/wx/socket.h index 0de0c81e43..36ad0f87d2 100644 --- a/interface/wx/socket.h +++ b/interface/wx/socket.h @@ -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()) */ diff --git a/src/common/socket.cpp b/src/common/socket.cpp index 37cd53783a..5fb8c291ae 100644 --- a/src/common/socket.cpp +++ b/src/common/socket.cpp @@ -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; }