-// These WaitXXX unctions do not depend on the event system any
-// longer; instead, they poll the socket, using GSocket_Select()
-// to check for the specified combination of event flags, until
-// an event occurs or until the timeout ellapses. The polling
-// loop calls PROCESS_EVENTS(), so this won't block the GUI.
-//
-// XXX: Should it honour the wxSOCKET_BLOCK flag ?
-//
-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
- if (!m_socket)
- return FALSE;
-
- // If it is not a server, it must be connected or establishing connection
- if ((m_type != SOCK_SERVER) && (!m_connected && !m_establishing))
- 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);
-
- // The order in which we check events is important; in particular,
- // GSOCKET_LOST events should be checked last (there might be still
- // data to read in the incoming queue even after the peer has closed
- // the connection).
-
- // Incoming connection (server) or connection established (client)
- if (result & GSOCK_CONNECTION_FLAG)
- {
- timer.Stop();
- m_connected = TRUE;
- m_establishing = FALSE;
- return TRUE;
- }
-
- // Input and output
- if ((result & GSOCK_INPUT_FLAG) || (result & GSOCK_OUTPUT_FLAG))
- {
- timer.Stop();
- return TRUE;
- }
-
- // Connection lost
- if (result & GSOCK_LOST_FLAG)
- {
- timer.Stop();
- Close();
- return TRUE;
- }
-
- // Wait more?
- if ((timeout == 0) || (m_interrupt))
- break;
- else
- PROCESS_EVENTS();
- }
+ wxSocketWaitModeChanger changeFlags(this, wxSOCKET_WAITALL);
+
+ msg.sig[0] = (unsigned char) 0xad;
+ msg.sig[1] = (unsigned char) 0xde;
+ msg.sig[2] = (unsigned char) 0xed;
+ msg.sig[3] = (unsigned char) 0xfe;
+
+ msg.len[0] = (unsigned char) (nbytes & 0xff);
+ msg.len[1] = (unsigned char) ((nbytes >> 8) & 0xff);
+ msg.len[2] = (unsigned char) ((nbytes >> 16) & 0xff);
+ msg.len[3] = (unsigned char) ((nbytes >> 24) & 0xff);
+
+ bool ok = false;
+ if ( DoWrite(&msg, sizeof(msg)) == sizeof(msg) )
+ {
+ m_lcount = DoWrite(buffer, nbytes);
+ if ( m_lcount == nbytes )
+ {
+ msg.sig[0] = (unsigned char) 0xed;
+ msg.sig[1] = (unsigned char) 0xfe;
+ msg.sig[2] = (unsigned char) 0xad;
+ msg.sig[3] = (unsigned char) 0xde;
+ msg.len[0] =
+ msg.len[1] =
+ msg.len[2] =
+ msg.len[3] = (char) 0;
+
+ if ( DoWrite(&msg, sizeof(msg)) == sizeof(msg))
+ ok = true;
+ }
+ }