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

operator  int ()

int

[const]

string  str ()

str

[const]

void  clear ()

clear

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

operator  HANDLE ()

HANDLE

[const]

operator  SOCKET ()

SOCKET

[const]

void  clear ()

clear

string  str ()

str

[const]

bool  is_valid ()

is_valid

[const]

WinFdType  type ()

type

[const]

bool  is_console ()

is_console

[const]

bool  is_process ()

is_process

[const]

bool  is_pipe ()

is_pipe

[const]

bool  is_socket ()

is_socket

[const]

bool  operator == (const XorpFd& rhand)

operator ==

[const]

bool  operator != (const XorpFd& rhand)

operator !=

[const]

bool  operator > (const XorpFd& rhand)

operator >

[const]

bool  operator < (const XorpFd& rhand)

operator <

[const]


Generated by: pavlin on kobe.xorp.net on Wed Jan 7 19:10:36 2009, using kdoc 2.0a54+XORP.