class XorpFd

XorpFd definition. More...

 
LOGO
 Annotated List  Files  Globals  Hierarchy  Index  Top

Public Types

Public Methods


Detailed Description

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).

 XorpFd ()

XorpFd

 XorpFd (int fd)

XorpFd

inline operator  int ()

int

[const]

inline string  str ()

str

[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 ()

XorpFd

 XorpFd (HANDLE h)

XorpFd

 XorpFd (long l)

XorpFd

 XorpFd (SOCKET s)

XorpFd

 XorpFd (const XorpFd& rhand)

XorpFd

inline operator  HANDLE ()

HANDLE

[const]

inline operator  SOCKET ()

SOCKET

[const]

inline void  clear ()

clear

inline string  str ()

str

[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 Mar 21 11:22:16 2007, using kdoc $.