]> git.saurik.com Git - wxWidgets.git/blob - src/gtk1/sockgtk.cpp
wxSplitterWindow mouse capture improvements and cleanup.
[wxWidgets.git] / src / gtk1 / sockgtk.cpp
1 ///////////////////////////////////////////////////////////////////////////////
2 // Name: gtk/gsockgtk.cpp
3 // Purpose: implementation of wxGTK-specific socket event handling
4 // Author: Guilhem Lavaux, Vadim Zeitlin
5 // Created: 1999
6 // RCS-ID: $Id$
7 // Copyright: (c) 1999, 2007 wxWidgets dev team
8 // Licence: wxWindows licence
9 ///////////////////////////////////////////////////////////////////////////////
10
11 // For compilers that support precompilation, includes "wx.h".
12 #include "wx/wxprec.h"
13
14 #if wxUSE_SOCKETS
15
16 #include <stdlib.h>
17 #include <stdio.h>
18
19 #include <gdk/gdk.h>
20 #include <glib.h>
21
22 #include "wx/private/socket.h"
23 #include "wx/apptrait.h"
24
25 extern "C" {
26 static
27 void wxSocket_GDK_Input(gpointer data,
28 gint WXUNUSED(source),
29 GdkInputCondition condition)
30 {
31 wxSocketImplUnix * const handler = static_cast<wxSocketImplUnix *>(data);
32
33 if ( condition & GDK_INPUT_READ )
34 {
35 handler->OnReadWaiting();
36
37 // we could have lost connection while reading in which case we
38 // shouldn't call OnWriteWaiting() as the socket is now closed and it
39 // would assert
40 if ( handler->m_fd == INVALID_SOCKET )
41 return;
42 }
43
44 if ( condition & GDK_INPUT_WRITE )
45 handler->OnWriteWaiting();
46 }
47 }
48
49 class GTKSocketManager : public wxSocketInputBasedManager
50 {
51 public:
52 virtual int AddInput(wxSocketImplUnix *handler, int fd, SocketDir d)
53 {
54 return gdk_input_add
55 (
56 fd,
57 d == FD_OUTPUT ? GDK_INPUT_WRITE : GDK_INPUT_READ,
58 wxSocket_GDK_Input,
59 handler
60 );
61 }
62
63 virtual void RemoveInput(int fd)
64 {
65 gdk_input_remove(fd);
66 }
67 };
68
69 wxSocketManager *wxGUIAppTraits::GetSocketManager()
70 {
71 static GTKSocketManager s_manager;
72 return &s_manager;
73 }
74
75 #endif // wxUSE_SOCKETS