-bool wxSocketBase::_Wait(long seconds, long milliseconds,
- wxSocketEventFlags flags)
-{
- GSocketEventFlags result;
- _wxSocketInternalTimer timer;
- long timeout;
- int state = -1;
-
- // Set this to TRUE to interrupt ongoing waits
- m_interrupt = FALSE;
-
- // Check for valid socket (GRG)
- if (!m_socket)
- return FALSE;
-
- // Check for valid timeout value
- if (seconds != -1)
- timeout = seconds * 1000 + milliseconds;
- else
- timeout = m_timeout * 1000;
-
- // Activate timer
- if (timeout)
- {
- timer.m_state = &state;
- timer.m_new_val = 0;
- timer.Start((int)timeout, TRUE);
- }
-
- // Active polling (without using events)
- //
- // NOTE: this duplicates some of the code in OnRequest (lost
- // connection and connection establishment handling) but this
- // doesn't hurt. It has to be here because the event might
- // be a bit delayed, and it has to be in OnRequest as well
- // because maybe the WaitXXX functions are not being used.
- //
- // Do this at least once (important if timeout == 0, when
- // we are just polling). Also, if just polling, do not yield.
- //
- while (state == -1)
- {
- result = GSocket_Select(m_socket, flags | GSOCK_LOST_FLAG);
-
- // Incoming connection (server) or connection established (client)
- if (result & GSOCK_CONNECTION_FLAG)
+ // Use either the provided timeout or the default timeout value associated
+ // with this socket.
+ //
+ // TODO: allow waiting forever, see #9443
+ const long timeout = seconds == -1 ? m_timeout * 1000
+ : seconds * 1000 + milliseconds;
+ const wxMilliClock_t timeEnd = wxGetLocalTimeMillis() + timeout;
+
+ // Get the active event loop which we'll use for the message dispatching
+ // when running in the main thread
+ wxEventLoopBase *eventLoop;
+ if ( wxIsMainThread() )