]> git.saurik.com Git - wxWidgets.git/commitdiff
documented how to use sockets in non-main thread (patch 951134)
authorVadim Zeitlin <vadim@wxwidgets.org>
Sun, 25 Jul 2004 12:41:14 +0000 (12:41 +0000)
committerVadim Zeitlin <vadim@wxwidgets.org>
Sun, 25 Jul 2004 12:41:14 +0000 (12:41 +0000)
git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@28464 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775

docs/latex/wx/socket.tex
src/common/socket.cpp

index 41936b4a603f415b085f1260be3adee84f1a6773..1c8d64aa7386d9cedfcfa059eeebf83b73af3467 100644 (file)
 wxSocketBase is the base class for all socket-related objects, and it
 defines all basic IO functionality.
 
+Note: (Workaround for implementation limitation for wxWidgets up to 2.5.x)
+If you want to use sockets or derived classes such as wxFTP in a secondary thread,
+call wxSocketBase::Initialize() (undocumented) from the main thread before creating 
+any sockets - in wxApp::OnInit for example. 
+See http://wiki.wxwidgets.org/wiki.pl?WxSocket or
+http://www.litwindow.com/knowhow/knowhow.html for more details.
+
 \wxheading{Derived from}
 
 \helpref{wxObject}{wxobject}
index 5e8f4ff8dec23f8d9196be1dd529c7b28ef55a30..bbbdc01e59faf100ce37ac5b2633c413e33cfd25 100644 (file)
@@ -122,6 +122,26 @@ bool wxSocketBase::Initialize()
 {
     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 =