]>
Commit | Line | Data |
---|---|---|
2804f77d | 1 | /////////////////////////////////////////////////////////////////////////////// |
80fdcdb9 | 2 | // Name: src/gtk/sockgtk.cpp |
2804f77d VZ |
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 | |
6bcc1145 | 8 | // (c) 2009 Vadim Zeitlin |
2804f77d VZ |
9 | // Licence: wxWindows licence |
10 | /////////////////////////////////////////////////////////////////////////////// | |
11 | ||
9b5f1895 WS |
12 | // For compilers that support precompilation, includes "wx.h". |
13 | #include "wx/wxprec.h" | |
180f9714 | 14 | |
6114fa03 | 15 | #if wxUSE_SOCKETS && defined(__UNIX__) |
180f9714 | 16 | |
2804f77d | 17 | #include "wx/apptrait.h" |
6bcc1145 | 18 | #include "wx/private/fdiomanager.h" |
180f9714 | 19 | |
385e8575 | 20 | #include <glib.h> |
65391c8f | 21 | |
865bb325 | 22 | extern "C" { |
385e8575 | 23 | static gboolean wxSocket_Input(GIOChannel*, GIOCondition condition, gpointer data) |
180f9714 | 24 | { |
6bcc1145 | 25 | wxFDIOHandler * const handler = static_cast<wxFDIOHandler *>(data); |
180f9714 | 26 | |
385e8575 | 27 | if (condition & G_IO_IN) |
ee0995b0 | 28 | { |
a9d859df | 29 | handler->OnReadWaiting(); |
ee0995b0 VZ |
30 | |
31 | // we could have lost connection while reading in which case we | |
32 | // shouldn't call OnWriteWaiting() as the socket is now closed and it | |
33 | // would assert | |
251e98cb | 34 | if ( !handler->IsOk() ) |
385e8575 | 35 | return true; |
ee0995b0 VZ |
36 | } |
37 | ||
385e8575 | 38 | if (condition & G_IO_OUT) |
a9d859df | 39 | handler->OnWriteWaiting(); |
385e8575 PC |
40 | |
41 | return true; | |
180f9714 | 42 | } |
865bb325 | 43 | } |
180f9714 | 44 | |
6bcc1145 | 45 | class GTKFDIOManager : public wxFDIOManager |
180f9714 | 46 | { |
2804f77d | 47 | public: |
6bcc1145 | 48 | virtual int AddInput(wxFDIOHandler *handler, int fd, Direction d) |
2804f77d | 49 | { |
385e8575 PC |
50 | return g_io_add_watch( |
51 | g_io_channel_unix_new(fd), | |
52 | d == OUTPUT ? G_IO_OUT : G_IO_IN, | |
53 | wxSocket_Input, | |
54 | handler); | |
2804f77d VZ |
55 | } |
56 | ||
6bcc1145 VZ |
57 | virtual void |
58 | RemoveInput(wxFDIOHandler* WXUNUSED(handler), int fd, Direction WXUNUSED(d)) | |
2804f77d | 59 | { |
385e8575 | 60 | g_source_remove(fd); |
2804f77d VZ |
61 | } |
62 | }; | |
63 | ||
6bcc1145 | 64 | wxFDIOManager *wxGUIAppTraits::GetFDIOManager() |
180f9714 | 65 | { |
6bcc1145 | 66 | static GTKFDIOManager s_manager; |
2804f77d | 67 | return &s_manager; |
180f9714 DE |
68 | } |
69 | ||
6114fa03 | 70 | #endif // wxUSE_SOCKETS && __UNIX__ |