// what to do within waits: we have 2 cases: from the main thread itself we
// have to call wxYield() to let the events (including the GUI events and the
-// low-level (not wxWindows) events from GSocket) be processed. From another
+// low-level (not wxWidgets) events from GSocket) be processed. From another
// thread it is enough to just call wxThread::Yield() which will give away the
// rest of our time slice: the explanation is that the events will be processed
// by the main thread anyhow, without calling wxYield(), but we don't want to
{
if ( !m_countInit++ )
{
+#ifdef __WXMSW__
+ /*
+ The following asserting might be neccessary for linux as well,
+ but I cannot verify this.
+ */
+ wxASSERT(wxThread::IsMain(),
+ wxT("To use sockets in a secondary thread, ")
+ wxT("call wxSocketBase::Initialize() from the main thread."));
+ /*
+ Details: Initialize() creates a hidden window as a sink for socket
+ events, such as 'read completed'. wxMSW has only one message loop
+ for the main thread. If Initialize is called in a secondary thread,
+ the socket window will be created for the secondary thread, but
+ since there is no message loop on this thread, it will never
+ receive events and all socket operations will time out.
+ BTW, the main thread must not be stopped using sleep or block
+ on a semaphore (a bad idea in any case) or socket operations
+ will time out.
+ */
+#endif
wxAppTraits *traits = wxAppConsole::GetInstance() ?
wxAppConsole::GetInstance()->GetTraits() : NULL;
GSocketGUIFunctionsTable *functions =
else
timeout = m_timeout * 1000;
+#if !defined(wxUSE_GUI) || !wxUSE_GUI
+ GSocket_SetTimeout(m_socket, timeout);
+#endif
+
// Wait in an active polling loop.
//
// NOTE: We duplicate some of the code in OnRequest, but this doesn't
GSOCK_LOST_FLAG);
}
+
bool wxSocketBase::WaitForWrite(long seconds, long milliseconds)
{
return _Wait(seconds, milliseconds, GSOCK_OUTPUT_FLAG);
return _Wait(seconds, milliseconds, GSOCK_CONNECTION_FLAG);
}
+bool wxSocketBase::GetOption(int level, int optname, void *optval, int *optlen)
+{
+ if (GSocket_GetSockOpt(m_socket, level, optname, optval, optlen)
+ != GSOCK_NOERROR)
+ {
+ return FALSE;
+ }
+ return TRUE;
+}
+
+bool wxSocketBase::SetOption(int level, int optname, const void *optval,
+ int optlen)
+{
+ if (GSocket_SetSockOpt(m_socket, level, optname, optval, optlen)
+ != GSOCK_NOERROR)
+ {
+ return FALSE;
+ }
+ return TRUE;
+}
+
// ==========================================================================
// wxSocketClient
// ==========================================================================
m_socket = GSocket_new();
if(!m_socket)
+ {
+ wxASSERT_MSG( 0, _T("datagram socket not new'd") );
return;
-
+ }
// Setup the socket as non connection oriented
+ GSocket_Unstreamed(m_socket);
GSocket_SetLocal(m_socket, addr.GetAddress());
if( GSocket_SetNonOriented(m_socket) != GSOCK_NOERROR )
{