]> git.saurik.com Git - wxWidgets.git/blame - src/gtk/sockgtk.cpp
Set missing Language: headers in PO files.
[wxWidgets.git] / src / gtk / sockgtk.cpp
CommitLineData
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
2804f77d 6// Copyright: (c) 1999, 2007 wxWidgets dev team
6bcc1145 7// (c) 2009 Vadim Zeitlin
2804f77d
VZ
8// Licence: wxWindows licence
9///////////////////////////////////////////////////////////////////////////////
10
9b5f1895
WS
11// For compilers that support precompilation, includes "wx.h".
12#include "wx/wxprec.h"
180f9714 13
6114fa03 14#if wxUSE_SOCKETS && defined(__UNIX__)
180f9714 15
2804f77d 16#include "wx/apptrait.h"
6bcc1145 17#include "wx/private/fdiomanager.h"
180f9714 18
385e8575 19#include <glib.h>
65391c8f 20
865bb325 21extern "C" {
385e8575 22static gboolean wxSocket_Input(GIOChannel*, GIOCondition condition, gpointer data)
180f9714 23{
6bcc1145 24 wxFDIOHandler * const handler = static_cast<wxFDIOHandler *>(data);
180f9714 25
385e8575 26 if (condition & G_IO_IN)
ee0995b0 27 {
a9d859df 28 handler->OnReadWaiting();
ee0995b0
VZ
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
251e98cb 33 if ( !handler->IsOk() )
385e8575 34 return true;
ee0995b0
VZ
35 }
36
385e8575 37 if (condition & G_IO_OUT)
a9d859df 38 handler->OnWriteWaiting();
385e8575
PC
39
40 return true;
180f9714 41}
865bb325 42}
180f9714 43
6bcc1145 44class GTKFDIOManager : public wxFDIOManager
180f9714 45{
2804f77d 46public:
6bcc1145 47 virtual int AddInput(wxFDIOHandler *handler, int fd, Direction d)
2804f77d 48 {
385e8575
PC
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);
2804f77d
VZ
54 }
55
6bcc1145
VZ
56 virtual void
57 RemoveInput(wxFDIOHandler* WXUNUSED(handler), int fd, Direction WXUNUSED(d))
2804f77d 58 {
385e8575 59 g_source_remove(fd);
2804f77d
VZ
60 }
61};
62
6bcc1145 63wxFDIOManager *wxGUIAppTraits::GetFDIOManager()
180f9714 64{
6bcc1145 65 static GTKFDIOManager s_manager;
2804f77d 66 return &s_manager;
180f9714
DE
67}
68
6114fa03 69#endif // wxUSE_SOCKETS && __UNIX__