X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/3c7789014106c9269b0f4ecc1a3071b14f351d3f..12b5f4b4d2d8a07962da7ba3b78c8c1ec2634a67:/src/common/socket.cpp diff --git a/src/common/socket.cpp b/src/common/socket.cpp index 3d5338425b..abe4f83810 100644 --- a/src/common/socket.cpp +++ b/src/common/socket.cpp @@ -42,6 +42,7 @@ #include "wx/stopwatch.h" #include "wx/thread.h" #include "wx/evtloop.h" +#include "wx/link.h" #include "wx/private/fd.h" #include "wx/private/socket.h" @@ -769,7 +770,8 @@ void wxSocketBase::Init() { // this Initialize() will be undone by wxSocketModule::OnExit(), all // the other calls to it should be matched by a call to Shutdown() - Initialize(); + if (!Initialize()) + wxLogError("Cannot initialize wxSocketBase"); } } @@ -1326,6 +1328,20 @@ wxSocketBase::DoWait(long timeout, wxSocketEventFlags flags) eventLoop = NULL; } + // Make sure the events we're interested in are enabled before waiting for + // them: this is really necessary here as otherwise this could happen: + // 1. DoRead(wxSOCKET_WAITALL) is called + // 2. There is nothing to read so DoWait(wxSOCKET_INPUT_FLAG) is called + // 3. Some, but not all data appears, wxSocketImplUnix::OnReadWaiting() + // is called and wxSOCKET_INPUT_FLAG events are disabled in it + // 4. Because of wxSOCKET_WAITALL we call DoWait() again but the events + // are still disabled and we block forever + // + // More elegant solution would be nice but for now simply re-enabling the + // events here will do + m_impl->ReenableEvents(flags & (wxSOCKET_INPUT_FLAG | wxSOCKET_OUTPUT_FLAG)); + + // Wait until we receive the event we're waiting for or the timeout expires // (but note that we always execute the loop at least once, even if timeout // is 0 as this is used for polling) @@ -1988,4 +2004,11 @@ private: IMPLEMENT_DYNAMIC_CLASS(wxSocketModule, wxModule) +#if defined(wxUSE_SELECT_DISPATCHER) && wxUSE_SELECT_DISPATCHER +// NOTE: we need to force linking against socketiohandler.cpp otherwise in +// static builds of wxWidgets the ManagerSetter::ManagerSetter ctor +// contained there wouldn't be ever called +wxFORCE_LINK_MODULE( socketiohandler ) +#endif + #endif // wxUSE_SOCKETS