]> git.saurik.com Git - wxWidgets.git/blobdiff - src/gtk1/sockgtk.cpp
Virtualize wxSocketImpl creation by routing it via wxSocketManager.
[wxWidgets.git] / src / gtk1 / sockgtk.cpp
index b8b1ecb61228a6ca8a24724d9b473610f210dec2..c8d449cfd86638627b813b39f108f03d8ed3614c 100644 (file)
@@ -28,26 +28,35 @@ void wxSocket_GDK_Input(gpointer data,
                         gint WXUNUSED(source),
                         GdkInputCondition condition)
 {
-  wxSocketImpl const *socket = static_cast<wxSocketImpl *>(data);
+    wxSocketImplUnix * const handler = static_cast<wxSocketImplUnix *>(data);
 
-  if ( condition & GDK_INPUT_READ )
-    socket->Detected_Read();
-  if ( condition & GDK_INPUT_WRITE )
-    socket->Detected_Write();
+    if ( condition & GDK_INPUT_READ )
+    {
+        handler->OnReadWaiting();
+
+        // we could have lost connection while reading in which case we
+        // shouldn't call OnWriteWaiting() as the socket is now closed and it
+        // would assert
+        if ( handler->m_fd == INVALID_SOCKET )
+            return;
+    }
+
+    if ( condition & GDK_INPUT_WRITE )
+        handler->OnWriteWaiting();
 }
 }
 
 class GTKSocketManager : public wxSocketInputBasedManager
 {
 public:
-    virtual int AddInput(wxSocketImpl *socket, SocketDir d)
+    virtual int AddInput(wxSocketImplUnix *handler, int fd, SocketDir d)
     {
         return gdk_input_add
                (
-                    socket->m_fd,
+                    fd,
                     d == FD_OUTPUT ? GDK_INPUT_WRITE : GDK_INPUT_READ,
                     wxSocket_GDK_Input,
-                    socket
+                    handler
                );
     }