]>
git.saurik.com Git - wxWidgets.git/blob - include/wx/unix/private/sockunix.h
1 /////////////////////////////////////////////////////////////////////////////
2 // Name: wx/unix/private/sockunix.h
3 // Purpose: wxSocketImpl implementation for Unix systems
4 // Authors: Guilhem Lavaux, Vadim Zeitlin
6 // Copyright: (c) 1997 Guilhem Lavaux
7 // (c) 2008 Vadim Zeitlin
8 // Licence: wxWindows licence
9 /////////////////////////////////////////////////////////////////////////////
11 #ifndef _WX_UNIX_GSOCKUNX_H_
12 #define _WX_UNIX_GSOCKUNX_H_
15 #include <sys/ioctl.h>
17 // Under older (Open)Solaris versions FIONBIO is declared in this header only.
18 // In the newer versions it's included by sys/ioctl.h but it's simpler to just
19 // include it always instead of testing for whether it is or not.
21 #include <sys/filio.h>
24 #include "wx/private/fdiomanager.h"
26 class wxSocketImplUnix
: public wxSocketImpl
,
30 wxSocketImplUnix(wxSocketBase
& wxsocket
)
31 : wxSocketImpl(wxsocket
)
37 virtual wxSocketError
GetLastError() const;
39 virtual void ReenableEvents(wxSocketEventFlags flags
)
41 // enable the notifications about input/output being available again in
42 // case they were disabled by OnRead/WriteWaiting()
44 // notice that we'd like to enable the events here only if there is
45 // nothing more left on the socket right now as otherwise we're going
46 // to get a "ready for whatever" notification immediately (well, during
47 // the next event loop iteration) and disable the event back again
48 // which is rather inefficient but unfortunately doing it like this
49 // doesn't work because the existing code (e.g. src/common/sckipc.cpp)
50 // expects to keep getting notifications about the data available from
51 // the socket even if it didn't read all the data the last time, so we
52 // absolutely have to continue generating them
56 // wxFDIOHandler methods
57 virtual void OnReadWaiting();
58 virtual void OnWriteWaiting();
59 virtual void OnExceptionWaiting();
60 virtual bool IsOk() const { return m_fd
!= INVALID_SOCKET
; }
63 virtual void DoClose()
70 virtual void UnblockAndRegisterWithEventLoop()
73 ioctl(m_fd
, FIONBIO
, &trueArg
);
78 // enable or disable notifications for socket input/output events
79 void EnableEvents(int flags
= wxSOCKET_INPUT_FLAG
| wxSOCKET_OUTPUT_FLAG
)
80 { DoEnableEvents(flags
, true); }
81 void DisableEvents(int flags
= wxSOCKET_INPUT_FLAG
| wxSOCKET_OUTPUT_FLAG
)
82 { DoEnableEvents(flags
, false); }
84 // really enable or disable socket input/output events
85 void DoEnableEvents(int flags
, bool enable
);
88 // descriptors for input and output event notification channels associated
93 // notify the associated wxSocket about a change in socket state and shut
94 // down the socket if the event is wxSOCKET_LOST
95 void OnStateChange(wxSocketNotify event
);
97 // check if there is any input available, return 1 if yes, 0 if no or -1 on
102 // give it access to our m_fds
103 friend class wxSocketFDBasedManager
;
106 // A version of wxSocketManager which uses FDs for socket IO: it is used by
107 // Unix console applications and some X11-like ports (wxGTK and wxMotif but not
108 // wxX11 currently) which implement their own port-specific wxFDIOManagers
109 class wxSocketFDBasedManager
: public wxSocketManager
112 wxSocketFDBasedManager()
114 m_fdioManager
= NULL
;
117 virtual bool OnInit();
118 virtual void OnExit() { }
120 virtual wxSocketImpl
*CreateSocket(wxSocketBase
& wxsocket
)
122 return new wxSocketImplUnix(wxsocket
);
125 virtual void Install_Callback(wxSocketImpl
*socket_
, wxSocketNotify event
);
126 virtual void Uninstall_Callback(wxSocketImpl
*socket_
, wxSocketNotify event
);
129 // get the FD index corresponding to the given wxSocketNotify
130 wxFDIOManager::Direction
131 GetDirForEvent(wxSocketImpl
*socket
, wxSocketNotify event
);
133 // access the FDs we store
134 int& FD(wxSocketImplUnix
*socket
, wxFDIOManager::Direction d
)
136 return socket
->m_fds
[d
];
139 wxFDIOManager
*m_fdioManager
;
141 wxDECLARE_NO_COPY_CLASS(wxSocketFDBasedManager
);
144 #endif /* _WX_UNIX_GSOCKUNX_H_ */