]>
Commit | Line | Data |
---|---|---|
2804f77d VZ |
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 | ||
9b5f1895 WS |
11 | // For compilers that support precompilation, includes "wx.h". |
12 | #include "wx/wxprec.h" | |
180f9714 DE |
13 | |
14 | #if wxUSE_SOCKETS | |
15 | ||
180f9714 DE |
16 | #include <stdlib.h> |
17 | #include <stdio.h> | |
18 | ||
19 | #include <gdk/gdk.h> | |
20 | #include <glib.h> | |
21 | ||
60913641 | 22 | #include "wx/private/socket.h" |
2804f77d | 23 | #include "wx/apptrait.h" |
180f9714 | 24 | |
865bb325 VZ |
25 | extern "C" { |
26 | static | |
51fe4b60 | 27 | void wxSocket_GDK_Input(gpointer data, |
e4161a2a | 28 | gint WXUNUSED(source), |
180f9714 DE |
29 | GdkInputCondition condition) |
30 | { | |
ee0995b0 | 31 | wxSocketImplUnix * const handler = static_cast<wxSocketImplUnix *>(data); |
180f9714 | 32 | |
51fe4b60 | 33 | if ( condition & GDK_INPUT_READ ) |
ee0995b0 | 34 | { |
a9d859df | 35 | handler->OnReadWaiting(); |
ee0995b0 VZ |
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 | ||
51fe4b60 | 44 | if ( condition & GDK_INPUT_WRITE ) |
a9d859df | 45 | handler->OnWriteWaiting(); |
180f9714 | 46 | } |
865bb325 | 47 | } |
180f9714 | 48 | |
51fe4b60 | 49 | class GTKSocketManager : public wxSocketInputBasedManager |
180f9714 | 50 | { |
2804f77d | 51 | public: |
ee0995b0 | 52 | virtual int AddInput(wxSocketImplUnix *handler, int fd, SocketDir d) |
2804f77d VZ |
53 | { |
54 | return gdk_input_add | |
55 | ( | |
a9d859df | 56 | fd, |
2804f77d | 57 | d == FD_OUTPUT ? GDK_INPUT_WRITE : GDK_INPUT_READ, |
51fe4b60 | 58 | wxSocket_GDK_Input, |
a9d859df | 59 | handler |
2804f77d VZ |
60 | ); |
61 | } | |
62 | ||
63 | virtual void RemoveInput(int fd) | |
64 | { | |
65 | gdk_input_remove(fd); | |
66 | } | |
67 | }; | |
68 | ||
51fe4b60 | 69 | wxSocketManager *wxGUIAppTraits::GetSocketManager() |
180f9714 | 70 | { |
2804f77d VZ |
71 | static GTKSocketManager s_manager; |
72 | return &s_manager; | |
180f9714 DE |
73 | } |
74 | ||
a59bbda1 | 75 | #endif // wxUSE_SOCKETS |