X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/33d925b0d96b60febb3ad39295a8da96294a5e16..8c03c8bed161882eb2ddbfa147fb5655fe75748d:/src/common/socket.cpp diff --git a/src/common/socket.cpp b/src/common/socket.cpp index a5b9eff86a..05f337bfc3 100644 --- a/src/common/socket.cpp +++ b/src/common/socket.cpp @@ -159,7 +159,7 @@ void wxSocketBase::Shutdown() { // we should be initialized wxASSERT_MSG( m_countInit, _T("extra call to Shutdown()") ); - if ( !--m_countInit ) + if ( --m_countInit == 0 ) { GSocket_Cleanup(); } @@ -694,6 +694,8 @@ bool wxSocketBase::_Wait(long seconds, else timeout = m_timeout * 1000; + bool has_event_loop = wxTheApp ? (wxTheApp->GetTraits() ? true : false) : false; + // Wait in an active polling loop. // // NOTE: We duplicate some of the code in OnRequest, but this doesn't @@ -709,14 +711,15 @@ bool wxSocketBase::_Wait(long seconds, bool done = false; bool valid_result = false; -#if !defined(wxUSE_GUI) || !wxUSE_GUI + if (!has_event_loop) + { // This is used to avoid a busy loop on wxBase - having a select // timeout of 50 ms per iteration should be enough. if (timeout > 50) m_socket->SetTimeout(50); else m_socket->SetTimeout(timeout); -#endif + } while (!done) { @@ -754,20 +757,22 @@ bool wxSocketBase::_Wait(long seconds, done = true; else { -#if !defined(wxUSE_GUI) || !wxUSE_GUI + if (has_event_loop) + { + PROCESS_EVENTS(); + } + else + { // If there's less than 50 ms left, just call select with that timeout. if (time_left < 50) m_socket->SetTimeout(time_left); -#else - PROCESS_EVENTS(); -#endif - } + } + } } // Set timeout back to original value (we overwrote it for polling) -#if !defined(wxUSE_GUI) || !wxUSE_GUI - m_socket->SetTimeout(m_timeout*1000); -#endif + if (!has_event_loop) + m_socket->SetTimeout(m_timeout*1000); return valid_result; } @@ -1198,13 +1203,14 @@ bool wxSocketBase::SetOption(int level, int optname, const void *optval, return true; } -bool wxSocketBase::SetLocal(wxSockAddress& local) +bool wxSocketBase::SetLocal(wxIPV4address& local) { GAddress* la = local.GetAddress(); + // If the address is valid, save it for use when we call Connect if (la && la->m_addr) { - m_socket->SetLocal(la); + m_localAddress = local; return true; } @@ -1269,6 +1275,12 @@ bool wxSocketClient::DoConnect(wxSockAddress& addr_man, wxSockAddress* local, bo m_socket->SetReusable(); } + // If no local address was passed and one has been set, use the one that was Set + if (!local && m_localAddress.GetAddress()) + { + local = &m_localAddress; + } + // Bind to the local IP address and port, when provided if (local) {