A couple of fixes to Brazilian Portuguese translations from Felipe.
[wxWidgets.git] / src / gtk / sockgtk.cpp
1 ///////////////////////////////////////////////////////////////////////////////
2 // Name: src/gtk/sockgtk.cpp
3 // Purpose: implementation of wxGTK-specific socket event handling
4 // Author: Guilhem Lavaux, Vadim Zeitlin
5 // Created: 1999
6 // Copyright: (c) 1999, 2007 wxWidgets dev team
7 // (c) 2009 Vadim Zeitlin
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 && defined(__UNIX__)
15
16 #include "wx/apptrait.h"
17 #include "wx/private/fdiomanager.h"
18
19 #include <glib.h>
20
21 extern "C" {
22 static gboolean wxSocket_Input(GIOChannel*, GIOCondition condition, gpointer data)
23 {
24 wxFDIOHandler * const handler = static_cast<wxFDIOHandler *>(data);
25
26 if (condition & G_IO_IN)
27 {
28 handler->OnReadWaiting();
29
30 // we could have lost connection while reading in which case we
31 // shouldn't call OnWriteWaiting() as the socket is now closed and it
32 // would assert
33 if ( !handler->IsOk() )
34 return true;
35 }
36
37 if (condition & G_IO_OUT)
38 handler->OnWriteWaiting();
39
40 return true;
41 }
42 }
43
44 class GTKFDIOManager : public wxFDIOManager
45 {
46 public:
47 virtual int AddInput(wxFDIOHandler *handler, int fd, Direction d)
48 {
49 return g_io_add_watch(
50 g_io_channel_unix_new(fd),
51 d == OUTPUT ? G_IO_OUT : G_IO_IN,
52 wxSocket_Input,
53 handler);
54 }
55
56 virtual void
57 RemoveInput(wxFDIOHandler* WXUNUSED(handler), int fd, Direction WXUNUSED(d))
58 {
59 g_source_remove(fd);
60 }
61 };
62
63 wxFDIOManager *wxGUIAppTraits::GetFDIOManager()
64 {
65 static GTKFDIOManager s_manager;
66 return &s_manager;
67 }
68
69 #endif // wxUSE_SOCKETS && __UNIX__