class XorpFd
|
XorpFd definition. More... |
|
|
Public Types
- enum WinFdType { FDTYPE_ERROR,
FDTYPE_FILE,
FDTYPE_CONSOLE,
FDTYPE_PIPE,
FDTYPE_SOCKET,
FDTYPE_PROCESS,
FDTYPE_OTHER
}
Public Methods
XorpFd is a wrapper class used to encapsulate a file descriptor.
It exists because of fundamental differences between UNIX and Windows
in terms of how the two families of operating systems deal with file
descriptors; in most flavours of UNIX, all file descriptors are
created equal, and may be represented using an 'int' type which is
usually 32 bits wide. In Windows, sockets are of type SOCKET, which
is a typedef alias of u_int; whereas all other system objects are
of type HANDLE, which in turn is a typedef alias of 'void *'.
The situation is made even more confusing by the fact that under
Windows, SOCKETs and HANDLEs may both be passed to various Windows
API functions.
In order to prevent a situation where the developer has to explicitly
cast all arguments passed to such functions (in order to keep the XORP
code base compatible across all the operating systems we support), we
define a wrapper class with casting operators for the underlying types.
When constructed, we always initialize the encapsulated file descriptor
to an invalid value appropriate to the OS under which we are running.
The non-Windows case is very simple. We do not define both sets of
functions at once so that the compiler will flag as an error those
situations where file descriptors are being used in a UNIX-like way,
i.e. where developers try to exploit the fact that UNIX file descriptors
are monotonically increasing integers.
XXX: Because Windows defines HANDLE in terms of a pointer, but also
defines SOCKET in terms of a 32-bit-wide unsigned integer, beware of
mixing 32-bit and 64-bit comparisons under Win64 when working with
socket APIs (or indeed any C/C++ library which will potentially do
work with sockets under Win64 such as libcomm).
inline operator int ()
| int |
[const]
[const]
inline void clear ()
| clear |
inline bool is_valid ()
| is_valid |
[const]
enum WinFdType { FDTYPE_ERROR,
FDTYPE_FILE,
FDTYPE_CONSOLE,
FDTYPE_PIPE,
FDTYPE_SOCKET,
FDTYPE_PROCESS,
FDTYPE_OTHER
}
| WinFdType |
XorpFd (const XorpFd& rhand)
| XorpFd |
inline operator HANDLE ()
| HANDLE |
[const]
inline operator SOCKET ()
| SOCKET |
[const]
inline void clear ()
| clear |
[const]
inline bool is_valid ()
| is_valid |
[const]
inline WinFdType type ()
| type |
[const]
inline bool is_console ()
| is_console |
[const]
inline bool is_process ()
| is_process |
[const]
inline bool is_pipe ()
| is_pipe |
[const]
inline bool is_socket ()
| is_socket |
[const]
inline bool operator == (const XorpFd& rhand)
| operator == |
[const]
inline bool operator != (const XorpFd& rhand)
| operator != |
[const]
inline bool operator > (const XorpFd& rhand)
| operator > |
[const]
inline bool operator < (const XorpFd& rhand)
| operator < |
[const]
Generated by: pavlin on possum.icir.org on Wed Aug 2 15:35:43 2006, using kdoc $.