]> git.saurik.com Git - wxWidgets.git/blobdiff - src/unix/gsocket.cpp
Added simple instructions and autogen.mk to rebuild configure script.
[wxWidgets.git] / src / unix / gsocket.cpp
index ab459eb018c6f7bc111dca21d7df46a4318a2954..becd67f59cfce20df21579175bf0860b66d7dbe3 100644 (file)
 #endif
 
 #ifndef __GSOCKET_STANDALONE__
 #endif
 
 #ifndef __GSOCKET_STANDALONE__
-#include "wx/setup.h"
+#include "wx/defs.h"
 #endif
 
 #if defined(__VISAGECPP__)
 #endif
 
 #if defined(__VISAGECPP__)
-/* Seems to be needed by Visual Age C++, though I don't see how it manages
-   to not break on including a C++ header into a plain C source file      */
-#include "wx/defs.h"
 #define BSD_SELECT /* use Berkley Sockets select */
 #endif
 
 #define BSD_SELECT /* use Berkley Sockets select */
 #endif
 
@@ -162,12 +159,11 @@ int _System soclose(int);
     #define UNMASK_SIGNAL() }
 
 #else
     #define UNMASK_SIGNAL() }
 
 #else
+    extern "C" { typedef void (*wxSigHandler)(int); }
 
     #define MASK_SIGNAL()                       \
     {                                           \
 
     #define MASK_SIGNAL()                       \
     {                                           \
-        void (*old_handler)(int);               \
-                                                \
-        old_handler = signal(SIGPIPE, SIG_IGN);
+        wxSigHandler old_handler = signal(SIGPIPE, SIG_IGN);
 
     #define UNMASK_SIGNAL()                     \
         signal(SIGPIPE, old_handler);           \
 
     #define UNMASK_SIGNAL()                     \
         signal(SIGPIPE, old_handler);           \
@@ -720,9 +716,15 @@ GSocketError GSocket::Connect(GSocketStream stream)
   /* Connect it to the peer address, with a timeout (see below) */
   ret = connect(m_fd, m_peer->m_addr, m_peer->m_len);
 
   /* Connect it to the peer address, with a timeout (see below) */
   ret = connect(m_fd, m_peer->m_addr, m_peer->m_len);
 
-  /* We only call Enable_Events if we know e aren't shutting down the socket */
-
-  if (m_non_blocking)
+  /* We only call Enable_Events if we know we aren't shutting down the socket.
+   * NB: Enable_Events needs to be called whether the socket is blocking or
+   * non-blocking, it just shouldn't be called prior to knowing there is a
+   * connection _if_ blocking sockets are being used.
+   * If connect above returns 0, we are already connected and need to make the
+   * call to Enable_Events now.  
+   */
+  
+  if (m_non_blocking || ret == 0)
   {
     gs_gui_functions->Enable_Events(this);
   }
   {
     gs_gui_functions->Enable_Events(this);
   }
@@ -969,6 +971,9 @@ GSocketEventFlags GSocket::Select(GSocketEventFlags flags)
 
     assert(this);
 
 
     assert(this);
 
+    if (m_fd == -1)
+        return (GSOCK_LOST_FLAG & flags);
+    
     /* Do not use a static struct, Linux can garble it */
     tv.tv_sec = m_timeout / 1000;
     tv.tv_usec = (m_timeout % 1000) * 1000;
     /* Do not use a static struct, Linux can garble it */
     tv.tv_sec = m_timeout / 1000;
     tv.tv_usec = (m_timeout % 1000) * 1000;