]> git.saurik.com Git - wxWidgets.git/blobdiff - include/wx/unix/private/sockunix.h
added .c_str() to wxStrlcpy() calls to fix wxUSE_STL build (closes #10252)
[wxWidgets.git] / include / wx / unix / private / sockunix.h
index 3dc2f9d6356161ea9968389b037fa7e01d27d8c9..dd83004505b230fb30f91a9aa1a48f6762fa64fe 100644 (file)
 
 #include <unistd.h>
 #include <sys/ioctl.h>
+#include "wx/private/fdiodispatcher.h"
 
-class wxSocketIOHandler;
-
-class wxSocketImplUnix : public wxSocketImpl
+class wxSocketImplUnix : public wxSocketImpl,
+                         public wxFDIOHandler
 {
 public:
-    wxSocketImplUnix(wxSocketBase& wxsocket);
+    wxSocketImplUnix(wxSocketBase& wxsocket)
+        : wxSocketImpl(wxsocket)
+    {
+        m_fds[0] =
+        m_fds[1] = -1;
+
+        m_use_events = false;
+        m_enabledCallbacks = 0;
+    }
 
     virtual void Shutdown();
     virtual wxSocketImpl *WaitConnection(wxSocketBase& wxsocket);
@@ -29,8 +37,19 @@ public:
     int Write(const char *buffer, int size);
     //attach or detach from main loop
     void Notify(bool flag);
-    void Detected_Read();
-    void Detected_Write();
+
+    // wxFDIOHandler methods
+    virtual void OnReadWaiting();
+    virtual void OnWriteWaiting();
+    virtual void OnExceptionWaiting();
+
+    // Unix-specific functions
+    bool HasAnyEnabledCallbacks() const { return m_enabledCallbacks != 0; }
+    void EnableCallback(wxFDIODispatcherEntryFlags flag)
+        { m_enabledCallbacks |= flag; }
+    void DisableCallback(wxFDIODispatcherEntryFlags flag)
+        { m_enabledCallbacks &= ~flag; }
+    int GetEnabledCallbacks() const { return m_enabledCallbacks; }
 
 private:
     virtual wxSocketError DoHandleConnect(int ret);
@@ -89,6 +108,7 @@ private:
     int Send_Stream(const char *buffer, int size);
     int Send_Dgram(const char *buffer, int size);
 
+
 protected:
     // true if socket should fire events
     bool m_use_events;
@@ -97,6 +117,13 @@ protected:
     // with the socket
     int m_fds[2];
 
+    // the events which are currently enabled for this socket, combination of
+    // wxFDIO_INPUT and wxFDIO_OUTPUT values
+    //
+    // TODO: this overlaps with m_detected but the semantics of the latter are
+    //       very unclear so I don't dare to remove it right now
+    int m_enabledCallbacks;
+
 private:
     // notify the associated wxSocket about a change in socket state and shut
     // down the socket if the event is wxSOCKET_LOST
@@ -114,12 +141,6 @@ public:
     virtual bool OnInit() { return true; }
     virtual void OnExit() { }
 
-    // allocate/free the storage we need
-    virtual wxSocketImpl *CreateSocket(wxSocketBase& wxsocket)
-    {
-        return new wxSocketImplUnix(wxsocket);
-    }
-
 protected:
     // identifies either input or output direction
     //
@@ -155,9 +176,9 @@ protected:
     }
 
     // access the FDs we store
-    int& FD(wxSocketImpl *socket, SocketDir d)
+    int& FD(wxSocketImplUnix *socket, SocketDir d)
     {
-        return static_cast<wxSocketImplUnix *>(socket)->m_fds[d];
+        return socket->m_fds[d];
     }
 };
 
@@ -166,8 +187,11 @@ protected:
 class wxSocketInputBasedManager : public wxSocketFDBasedManager
 {
 public:
-    virtual void Install_Callback(wxSocketImpl *socket, wxSocketNotify event)
+    virtual void Install_Callback(wxSocketImpl *socket_, wxSocketNotify event)
     {
+        wxSocketImplUnix * const
+            socket = static_cast<wxSocketImplUnix *>(socket_);
+
         wxCHECK_RET( socket->m_fd != -1,
                         "shouldn't be called on invalid socket" );
 
@@ -177,11 +201,14 @@ public:
         if ( fd != -1 )
             RemoveInput(fd);
 
-        fd = AddInput(socket, d);
+        fd = AddInput(socket, socket->m_fd, d);
     }
 
-    virtual void Uninstall_Callback(wxSocketImpl *socket, wxSocketNotify event)
+    virtual void Uninstall_Callback(wxSocketImpl *socket_, wxSocketNotify event)
     {
+        wxSocketImplUnix * const
+            socket = static_cast<wxSocketImplUnix *>(socket_);
+
         const SocketDir d = GetDirForEvent(socket, event);
 
         int& fd = FD(socket, d);
@@ -195,7 +222,7 @@ public:
 private:
     // these functions map directly to XtAdd/RemoveInput() or
     // gdk_input_add/remove()
-    virtual int AddInput(wxSocketImpl *socket, SocketDir d) = 0;
+    virtual int AddInput(wxFDIOHandler *handler, int fd, SocketDir d) = 0;
     virtual void RemoveInput(int fd) = 0;
 };