Rudiments: filedescriptor Class Reference

Rudiments

- Main Page
- Classes

- Class List
- Class Hierarchy
- Class Members

Public Member Functions | Static Public Member Functions | List of all members
filedescriptor Class Reference

Inherited by client, file, serialport, server, and stdiofiledescriptor.

## Public Member Functions
| filedescriptor ()
| filedescriptor (const filedescriptor &f)
filedescriptor & | operator= (const filedescriptor &f)
virtual | ~filedescriptor ()
virtual bool | close ()
int32_t | getFileDescriptor () const
void | setFileDescriptor (int32_t filedesc)
int32_t | duplicate () const
bool | duplicate (int32_t newfd) const
void | setSecurityContext (securitycontext *ctx)
securitycontext * | getSecurityContext ()
virtual bool | supportsBlockingNonBlockingModes ()
virtual bool | useNonBlockingMode () const
virtual bool | useBlockingMode () const
virtual bool | isUsingNonBlockingMode () const
ssize_t | write (uint16_t number) const
ssize_t | write (uint32_t number) const
ssize_t | write (uint64_t number) const
ssize_t | write (int16_t number) const
ssize_t | write (int32_t number) const
ssize_t | write (int64_t number) const
ssize_t | write (float number) const
ssize_t | write (double number) const
ssize_t | write (unsigned char character) const
ssize_t | write (char character) const
ssize_t | write (bool value) const
ssize_t | write (const unsigned char *string) const
ssize_t | write (const char *string) const
ssize_t | write (const unsigned char *string, size_t size) const
ssize_t | write (const char *string, size_t size) const
ssize_t | write (const void *buffer, size_t size) const
ssize_t | write (uint16_t number, int32_t sec, int32_t usec) const
ssize_t | write (uint32_t number, int32_t sec, int32_t usec) const
ssize_t | write (uint64_t number, int32_t sec, int32_t usec) const
ssize_t | write (int16_t number, int32_t sec, int32_t usec) const
ssize_t | write (int32_t number, int32_t sec, int32_t usec) const
ssize_t | write (int64_t number, int32_t sec, int32_t usec) const
ssize_t | write (float number, int32_t sec, int32_t usec) const
ssize_t | write (double number, int32_t sec, int32_t usec) const
ssize_t | write (unsigned char character, int32_t sec, int32_t usec) const
ssize_t | write (char character, int32_t sec, int32_t usec) const
ssize_t | write (bool value, int32_t sec, int32_t usec) const
ssize_t | write (const unsigned char *string, int32_t sec, int32_t usec) const
ssize_t | write (const char *string, int32_t sec, int32_t usec) const
ssize_t | write (const unsigned char *string, size_t size, int32_t sec, int32_t usec) const
ssize_t | write (const char *string, size_t size, int32_t sec, int32_t usec) const
ssize_t | write (const void *buffer, size_t size, int32_t sec, int32_t usec) const
size_t | printf (const char *format,...)
size_t | printf (const char *format, va_list *argp)
void | safePrint (unsigned char c)
void | safePrint (const unsigned char *str)
void | safePrint (const unsigned char *str, int32_t length)
void | safePrint (char c)
void | safePrint (const char *str)
void | safePrint (const char *str, int32_t length)
void | printBits (unsigned char value)
void | printBits (uint16_t value)
void | printBits (uint32_t value)
void | printBits (uint64_t value)
void | printBits (char value)
void | printBits (int16_t value)
void | printBits (int32_t value)
void | printBits (int64_t value)
void | printBits (unsigned char *bits, uint64_t size)
ssize_t | read (uint16_t *buffer)
ssize_t | read (uint32_t *buffer)
ssize_t | read (uint64_t *buffer)
ssize_t | read (int16_t *buffer)
ssize_t | read (int32_t *buffer)
ssize_t | read (int64_t *buffer)
ssize_t | read (float *buffer)
ssize_t | read (double *buffer)
ssize_t | read (unsigned char *buffer)
ssize_t | read (char *buffer)
ssize_t | read (bool *buffer)
ssize_t | read (unsigned char *buffer, size_t size)
ssize_t | read (char *buffer, size_t size)
ssize_t | read (void *buf, size_t size)
ssize_t | read (char **buffer, const char *terminator)
ssize_t | read (char **buffer, const char *terminator, size_t maxbytes)
ssize_t | read (uint16_t *buffer, int32_t sec, int32_t usec)
ssize_t | read (uint32_t *buffer, int32_t sec, int32_t usec)
ssize_t | read (uint64_t *buffer, int32_t sec, int32_t usec)
ssize_t | read (int16_t *buffer, int32_t sec, int32_t usec)
ssize_t | read (int32_t *buffer, int32_t sec, int32_t usec)
ssize_t | read (int64_t *buffer, int32_t sec, int32_t usec)
ssize_t | read (float *buffer, int32_t sec, int32_t usec)
ssize_t | read (double *buffer, int32_t sec, int32_t usec)
ssize_t | read (unsigned char *buffer, int32_t sec, int32_t usec)
ssize_t | read (char *buffer, int32_t sec, int32_t usec)
ssize_t | read (bool *buffer, int32_t sec, int32_t usec)
ssize_t | read (unsigned char *buffer, size_t size, int32_t sec, int32_t usec)
ssize_t | read (char *buffer, size_t size, int32_t sec, int32_t usec)
ssize_t | read (void *buf, size_t size, int32_t sec, int32_t usec)
ssize_t | read (char **buffer, const char *terminator, int32_t sec, int32_t usec)
ssize_t | read (char **buffer, const char *terminator, size_t maxbytes, int32_t sec, int32_t usec)
ssize_t | read (char **buffer, const char *terminator, size_t maxbytes, char escapechar, int32_t sec, int32_t usec)
int32_t | waitForNonBlockingRead (int32_t sec, int32_t usec) const
int32_t | waitForNonBlockingWrite (int32_t sec, int32_t usec) const
void | retryInterruptedReads ()
void | dontRetryInterruptedReads ()
bool | getRetryInterruptedReads () const
void | retryInterruptedWrites ()
void | dontRetryInterruptedWrites ()
bool | getRetryInterruptedWrites () const
void | retryInterruptedWaits ()
void | dontRetryInterruptedWaits ()
bool | getRetryInterruptedWaits () const
void | retryInterruptedFcntl ()
void | dontRetryInterruptedFcntl ()
bool | getRetryInterruptedFcntl () const
void | retryInterruptedIoctl ()
void | dontRetryInterruptedIoctl ()
bool | getRetryInterruptedIoctl () const
void | allowShortReads ()
void | dontAllowShortReads ()
void | allowShortWrites ()
void | dontAllowShortWrites ()
virtual bool | passFileDescriptor (int32_t fd)
virtual bool | receiveFileDescriptor (int32_t *fd)
virtual bool | passSocket (int32_t sock)
virtual bool | receiveSocket (int32_t *sock)
void | translateByteOrder ()
void | dontTranslateByteOrder ()
virtual int32_t | fCntl (int32_t command, long arg) const
virtual int32_t | ioCtl (int32_t command, void *arg) const
bool | useNaglesAlgorithm ()
bool | dontUseNaglesAlgorithm ()
bool | setTcpWriteBufferSize (int32_t size)
bool | getTcpWriteBufferSize (int32_t *size)
bool | setTcpReadBufferSize (int32_t size)
bool | getTcpReadBufferSize (int32_t *size)
bool | disableIPv4 ()
bool | enableIPv4 ()
const char * | getType () const
char * | getPeerAddress () const
bool | setWriteBufferSize (ssize_t size) const
bool | flushWriteBuffer (int32_t sec, int32_t usec) const
bool | setReadBufferSize (ssize_t size) const
bool | closeOnExec ()
bool | dontCloseOnExec ()
bool | getCloseOnExec ()

## Static Public Member Functions
static uint16_t | hostToNet (uint16_t value)
static uint32_t | hostToNet (uint32_t value)
static uint64_t | hostToNet (uint64_t value)
static uint16_t | netToHost (uint16_t value)
static uint32_t | netToHost (uint32_t value)
static uint64_t | netToHost (uint64_t value)

## Detailed Description

The filedescriptor class is a base class for other classes that utilize file descriptors.

## Constructor & Destructor Documentation

filedescriptor::filedescriptor | ( |  | ) |

Creates an instance of the filedescriptor class.

filedescriptor::filedescriptor | ( | const filedescriptor & | f | ) |

Creates an instance of the filedescriptor class that is a copy of "f".

virtual filedescriptor::~filedescriptor | ( |  | ) |
| virtual

Deletes this instance of the filedescriptor class. Calls close() if it hasn't already been called.

## Member Function Documentation

void filedescriptor::allowShortReads | ( |  | ) |

By default, read() will attempt to read the specified number of bytes from the file descriptor, even if several passes are necessary.

This method causes a read() to attempt only a single pass and return the number of bytes that were read during that pass whether the specified number of bytes were read or not.

Note that reads longer than SSIZE_MAX will only attempt to read SSIZE_MAX bytes.

void filedescriptor::allowShortWrites | ( |  | ) |

By default, write() will attempt to write the specified number of bytes from the file descriptor, in several passes if necessary.

This method causes a write() to attempt only a single pass and return the number of bytes that were written during that pass whether the specified number of bytes were written or not.

Note that writes longer than SSIZE_MAX will only attempt to write SSIZE_MAX bytes.

virtual bool filedescriptor::close | ( |  | ) |
| virtual

Closes the file descriptor. Returns true on success and false on failure.

Reimplemented in unixsocketclient, modemserver, and modemclient.

bool filedescriptor::closeOnExec | ( |  | ) |

If the close-on-exec status is false (the default), then the file descriptor will remain open across an execve() call, otherwise it will be closed.

This method sets the close-on-exec status to true.

bool filedescriptor::disableIPv4 | ( |  | ) |

Disables IPv4 on this file descriptor, only IPv6 will be used. This is only useful for TCP Socket file descriptors. Returns true on success and false on failure.

void filedescriptor::dontAllowShortReads | ( |  | ) |

By default, read() will attempt to read the specified number of bytes from the file descriptor, even if several passes are necessary.

This method causes that default behavior to be observed.

void filedescriptor::dontAllowShortWrites | ( |  | ) |

By default, write() will attempt to write the specified number of bytes from the file descriptor, even if several passes are necessary.

This method causes that default behavior to be observed.

bool filedescriptor::dontCloseOnExec | ( |  | ) |

If the close-on-exec status is false (the default), then the file descriptor will remain open across an execve() call, otherwise it will be closed.

This method sets the close-on-exec status to false (the default).

void filedescriptor::dontRetryInterruptedFcntl | ( |  | ) |

Causes fcntl operations not to be automatically retried if interrupted by a signal. If this is set, a fcntl is occurring and a signal interrupts it, the fcntl fails, the system error is set to EINTR and the fcntl must be retried.

void filedescriptor::dontRetryInterruptedIoctl | ( |  | ) |

Causes ioctl operations not to be automatically retried if interrupted by a signal. If this is set, a ioctl is occurring and a signal interrupts it, the ioctl fails, the system error is set to EINTR and the ioctl must be retried.

void filedescriptor::dontRetryInterruptedReads | ( |  | ) |

Causes reads not to automatically retry if interrupted by a signal. This is the default behavior. By default, if a read is occurring and a signal interrupts it, the read fails, the system error is set to EINTR and the read must be retried.

void filedescriptor::dontRetryInterruptedWaits | ( |  | ) |

Causes wait operations not to be automatically retried if interrupted by a signal. If this is set, a wait is occurring and a signal interrupts it, the wait fails, the system error is set to EINTR and the wait must be retried.

void filedescriptor::dontRetryInterruptedWrites | ( |  | ) |

Causes writes not to automatically retry if interrupted by a signal. This is the default behavior. By default, if a write is occurring and a signal interrupts it, the write fails, the system error is set to EINTR and the write must be retried.

void filedescriptor::dontTranslateByteOrder | ( |  | ) |

Don't translate integers from native byte order to network byte order during writes and vice-versa during reads. This is the default behavior.

bool filedescriptor::dontUseNaglesAlgorithm | ( |  | ) |

Causes all write()'s to be sent immediately. (disables Nagle's algorithm)

Returns true on success and false on failure.

int32_t filedescriptor::duplicate | ( |  | ) | const

Duplicates the file descriptor and returns the handle of the duplicate descriptor. The old and new descriptors may be used interchangeably, they share locks, position pointers, flags (except the close-on-exec flag), etc.

Returns the lowest-numbered unused descriptor on success or -1 on failure.

bool filedescriptor::duplicate | ( | int32_t | newfd | ) | const

Sets file descriptor handle "newfd" to be a duplicate of this file descriptor. If "newfd" is already open, it will be closed first.

Returns true on success and false on failure.

bool filedescriptor::enableIPv4 | ( |  | ) |

Enables IPv4 (in addition to IPv6) on this file descriptor (the default). This is only useful for TCP Socket file descriptors. Returns true on success and false on failure.

virtual int32_t filedescriptor::fCntl | ( | int32_t | command,
|  | long | arg
| ) |  | const
| virtual

Use the fcntl() system call to perform various low-level file descriptor operations.

bool filedescriptor::flushWriteBuffer | ( | int32_t | sec,
|  | int32_t | usec
| ) |  | const

If an application does many small writes, the overhead of all of those system calls can slow the application down substantially. To address that issue, the filedescriptor class can buffer data passed in to any of it's write() methods and only make system calls when the buffer is full or when it's flushed manually. Note that when using buffered writes, no data is actually written to the file descriptor until the buffer is full or until it's flushed manually.

Do not confuse this buffer with the tcp write buffer. The tcp write buffer resides in kernel space, is populated by the write() system call in an analagous manner and is used to minimize network latency, not application latency due to system calls. This buffer is in user space and populated prior to the write() system call.

This method causes the contents of the write buffer to be written to the filedescriptor immediately.

Returns true on success and false on failure.

If the buffer cannot be flushed within "sec" seconds and "usec" microseconds, then the method will fail. Set either "sec" or "usec" to -1 to disable the timeout and allow the method to block until the buffer has been flushed.

bool filedescriptor::getCloseOnExec | ( |  | ) |

If the close-on-exec status is false (the default), then the file descriptor will remain open across an execve() call, otherwise it will be closed.

This method returns true if the close-on-exec status is set to true and false otherwise.

int32_t filedescriptor::getFileDescriptor | ( |  | ) | const

Returns the file descriptor.

char* filedescriptor::getPeerAddress | ( |  | ) | const

Returns the IP address of the client at the other end of the connection if the filedescriptor is an inet socket or NULL otherwise.

Note that the buffer for the address is allocated internally and must be freed by the calling program.

bool filedescriptor::getRetryInterruptedFcntl | ( |  | ) | const

Returns true if interrupted calls to fcntl will be retried and false otherwise.

bool filedescriptor::getRetryInterruptedIoctl | ( |  | ) | const

Returns true if interrupted calls to ioctl will be retried and false otherwise.

bool filedescriptor::getRetryInterruptedReads | ( |  | ) | const

Returns true if interrupted reads will be retried and false otherwise.

bool filedescriptor::getRetryInterruptedWaits | ( |  | ) | const

Returns true if interrupted waits will be retried and false otherwise.

bool filedescriptor::getRetryInterruptedWrites | ( |  | ) | const

Returns true if interrupted writes will be retried and false otherwise.

securitycontext* filedescriptor::getSecurityContext | ( |  | ) |

Returns the securitycontext currently associated with the filedescriptor or NULL if none is currently associated.

bool filedescriptor::getTcpReadBufferSize | ( | int32_t * | size | ) |

Fetches the size of the kernel's TCP read buffer (in bytes) into buffer "size". This is only useful for TCP socket file descriptors. Returns true on success and false on failure.

bool filedescriptor::getTcpWriteBufferSize | ( | int32_t * | size | ) |

Fetches the size of the kernel's TCP write buffer (in bytes) into buffer "size". This is only useful for TCP socket file descriptors. Returns true on success and false on failure.

const char* filedescriptor::getType | ( |  | ) | const

Returns a string representing the type of the filedescriptor. This is "filedescriptor" by default but a child class may override this method and return something else.

static uint16_t filedescriptor::hostToNet | ( | uint16_t | value | ) |
| static

Converts an unsigned 16-bit integer from host byte order to network byte order.

static uint32_t filedescriptor::hostToNet | ( | uint32_t | value | ) |
| static

Converts an unsigned 32-bit integer from host byte order to network byte order.

static uint64_t filedescriptor::hostToNet | ( | uint64_t | value | ) |
| static

Converts an unsigned 64-bit integer from host byte order to network byte order.

virtual int32_t filedescriptor::ioCtl | ( | int32_t | command,
|  | void * | arg
| ) |  | const
| virtual

Use the ioctl() system call to perform various low-level file descriptor operations.

Reimplemented in socketserver, and socketclient.

virtual bool filedescriptor::isUsingNonBlockingMode | ( |  | ) | const
| virtual

Returns true if the file descriptor is in non-blocking mode and false otherwise.

Reimplemented in socketserver, and socketclient.

static uint16_t filedescriptor::netToHost | ( | uint16_t | value | ) |
| static

Converts an unsigned 16-bit integer from network byte order to host byte order.

static uint32_t filedescriptor::netToHost | ( | uint32_t | value | ) |
| static

Converts an unsigned 32-bit integer from network byte order to host byte order.

static uint64_t filedescriptor::netToHost | ( | uint64_t | value | ) |
| static

Converts an unsigned 64-bit integer from network byte order to host byte order.

filedescriptor& filedescriptor::operator= | ( | const filedescriptor & | f | ) |

Makes this instance of the filedescriptor class identical to "f".

virtual bool filedescriptor::passFileDescriptor | ( | int32_t | fd | ) |
| virtual

Sends file descriptor "fd" to the file descriptor. This is useful for passing an open file descriptor from one process to another over a unix socket, for example.

virtual bool filedescriptor::passSocket | ( | int32_t | sock | ) |
| virtual

Sends socket "sock" to the file descriptor. This is useful for passing an open socket from one process to another over a unix socket, for example.

void filedescriptor::printBits | ( | unsigned char | value | ) |

Prints "value" to the file descriptor as a string of ones and zeros.

void filedescriptor::printBits | ( | uint16_t | value | ) |

Prints "value" to the file descriptor as a string of ones and zeros.

void filedescriptor::printBits | ( | uint32_t | value | ) |

Prints "value" to the file descriptor as a string of ones and zeros.

void filedescriptor::printBits | ( | uint64_t | value | ) |

Prints "value" to the file descriptor as a string of ones and zeros.

void filedescriptor::printBits | ( | char | value | ) |

Prints "value" to the file descriptor as a string of ones and zeros.

void filedescriptor::printBits | ( | int16_t | value | ) |

Prints "value" to the file descriptor as a string of ones and zeros.

void filedescriptor::printBits | ( | int32_t | value | ) |

Prints "value" to the file descriptor as a string of ones and zeros.

void filedescriptor::printBits | ( | int64_t | value | ) |

Prints "value" to the file descriptor as a string of ones and zeros.

void filedescriptor::printBits | ( | unsigned char * | bits,
|  | uint64_t | size
| ) |  |

Prints "value" to the file descriptor as a string of ones and zeros.

size_t filedescriptor::printf | ( | const char * | format,
|  |  | ...
| ) |  |

Prints "..." to the filedescriptor using "format" which should comply with standard printf formatting rules.

size_t filedescriptor::printf | ( | const char * | format,
|  | va_list * | argp
| ) |  |

Prints "argp" to the filedescriptor using "format" which should comply with standard printf formatting rules.

Note that argp is a pointer to a va_list, not just a va_list.

ssize_t filedescriptor::read | ( | uint16_t * | buffer | ) |

Reads an unsigned 16-bit integer from the file descriptor into "buffer". Returns the number of bytes that were successfully read or RESULT_ERROR if an error occurred.

ssize_t filedescriptor::read | ( | uint32_t * | buffer | ) |

Reads an unsigned 32-bit integer from the file descriptor into "buffer". Returns the number of bytes that were successfully read or RESULT_ERROR if an error occurred.

ssize_t filedescriptor::read | ( | uint64_t * | buffer | ) |

Reads an unsigned 64-bit integer from the file descriptor into "buffer". Returns the number of bytes that were successfully read or RESULT_ERROR if an error occurred.

ssize_t filedescriptor::read | ( | int16_t * | buffer | ) |

Reads a 16-bit integer from the file descriptor into "buffer". Returns the number of bytes that were successfully read or RESULT_ERROR if an error occurred.

ssize_t filedescriptor::read | ( | int32_t * | buffer | ) |

Reads a 32-bit integer from the file descriptor into "buffer". Returns the number of bytes that were successfully read or RESULT_ERROR if an error occurred.

ssize_t filedescriptor::read | ( | int64_t * | buffer | ) |

Reads a 64-bit integer from the file descriptor into "buffer". Returns the number of bytes that were successfully read or RESULT_ERROR if an error occurred.

ssize_t filedescriptor::read | ( | float * | buffer | ) |

Reads a floating point number from the file descriptor into "buffer". Returns the number of bytes that were successfully read or RESULT_ERROR if an error occurred.

ssize_t filedescriptor::read | ( | double * | buffer | ) |

Reads a double-precision floating point number from the file descriptor into "buffer". Returns the number of bytes that were successfully read or RESULT_ERROR if an error occurred.

ssize_t filedescriptor::read | ( | unsigned char * | buffer | ) |

Reads an unsigned character from the file descriptor into "buffer". Returns the number of bytes that were successfully read or RESULT_ERROR if an error occurred.

ssize_t filedescriptor::read | ( | char * | buffer | ) |

Reads an character from the file descriptor into "buffer". Returns the number of bytes that were successfully read or RESULT_ERROR if an error occurred.

ssize_t filedescriptor::read | ( | bool * | buffer | ) |

Reads a boolean value from the file descriptor into "buffer". Returns the number of bytes that were successfully read or RESULT_ERROR if an error occurred.

ssize_t filedescriptor::read | ( | unsigned char * | buffer,
|  | size_t | size
| ) |  |

Reads "size" unsigned characters from the file descriptor into "buffer". Returns the number of bytes that were successfully read or RESULT_ERROR if an error occurred.

ssize_t filedescriptor::read | ( | char * | buffer,
|  | size_t | size
| ) |  |

Reads "size" characters from the file descriptor into "buffer". Returns the number of bytes that were successfully read or RESULT_ERROR if an error occurred.

ssize_t filedescriptor::read | ( | void * | buf,
|  | size_t | size
| ) |  |

Reads "size" bytes from the file descriptor into "buf". Returns the number of bytes that were successfully read or RESULT_ERROR if an error occurred.

ssize_t filedescriptor::read | ( | char ** | buffer,
|  | const char * | terminator
| ) |  |

Reads from the file desciptor into "buffer" until "terminator" is encountered.

Note that "buffer" is allocated internally and must be freed by the calling program.

Returns the number of bytes that were read or RESULT_ERROR if an error occurred.

ssize_t filedescriptor::read | ( | char ** | buffer,
|  | const char * | terminator,
|  | size_t | maxbytes
| ) |  |

Reads from the file desciptor into "buffer" until "terminator" is encountered.

Note that "buffer" is allocated internally and must be freed by the calling program.

Returns the number of bytes that were read, RESULT_ERROR if an error occurred or RESULT_MAX if maxbytes were read before the terminator was encountered.

Setting maxbytes to 0 disables it.

ssize_t filedescriptor::read | ( | uint16_t * | buffer,
|  | int32_t | sec,
|  | int32_t | usec
| ) |  |

Reads an unsigned 16-bit integer from the file descriptor into "buffer" with a timeout of "sec" seconds and "usec" microseconds. Returns the number of bytes that were successfully read, RESULT_ERROR if an error occurred or RESULT_TIMEOUT if a timeout occurred.

ssize_t filedescriptor::read | ( | uint32_t * | buffer,
|  | int32_t | sec,
|  | int32_t | usec
| ) |  |

Reads an unsigned 32-bit integer from the file descriptor into "buffer" with a timeout of "sec" seconds and "usec" microseconds. Returns the number of bytes that were successfully read, RESULT_ERROR if an error occurred or RESULT_TIMEOUT if a timeout occurred.

ssize_t filedescriptor::read | ( | uint64_t * | buffer,
|  | int32_t | sec,
|  | int32_t | usec
| ) |  |

Reads an unsigned 64-bit integer from the file descriptor into "buffer" with a timeout of "sec" seconds and "usec" microseconds. Returns the number of bytes that were successfully read, RESULT_ERROR if an error occurred or RESULT_TIMEOUT if a timeout occurred.

ssize_t filedescriptor::read | ( | int16_t * | buffer,
|  | int32_t | sec,
|  | int32_t | usec
| ) |  |

Reads a 16-bit integer from the file descriptor into "buffer" with a timeout of "sec" seconds and "usec" microseconds. Returns the number of bytes that were successfully read, RESULT_ERROR if an error occurred or RESULT_TIMEOUT if a timeout occurred.

ssize_t filedescriptor::read | ( | int32_t * | buffer,
|  | int32_t | sec,
|  | int32_t | usec
| ) |  |

Reads a 32-bit integer from the file descriptor into "buffer" with a timeout of "sec" seconds and "usec" microseconds. Returns the number of bytes that were successfully read, RESULT_ERROR if an error occurred or RESULT_TIMEOUT if a timeout occurred.

ssize_t filedescriptor::read | ( | int64_t * | buffer,
|  | int32_t | sec,
|  | int32_t | usec
| ) |  |

Reads a 64-bit integer from the file descriptor into "buffer" with a timeout of "sec" seconds and "usec" microseconds. Returns the number of bytes that were successfully read, RESULT_ERROR if an error occurred or RESULT_TIMEOUT if a timeout occurred.

ssize_t filedescriptor::read | ( | float * | buffer,
|  | int32_t | sec,
|  | int32_t | usec
| ) |  |

Reads a floating point number from the file descriptor into "buffer" with a timeout of "sec" seconds and "usec" microseconds. Returns the number of bytes that were successfully read, RESULT_ERROR if an error occurred or RESULT_TIMEOUT if a timeout occurred.

ssize_t filedescriptor::read | ( | double * | buffer,
|  | int32_t | sec,
|  | int32_t | usec
| ) |  |

Reads a double-precision floating point number from the file descriptor into "buffer" with a timeout of "sec" seconds and "usec" microseconds. Returns the number of bytes that were successfully read, RESULT_ERROR if an error occurred or RESULT_TIMEOUT if a timeout occurred.

ssize_t filedescriptor::read | ( | unsigned char * | buffer,
|  | int32_t | sec,
|  | int32_t | usec
| ) |  |

Reads an unsigned character from the file descriptor into "buffer" with a timeout of "sec" seconds and "usec" microseconds. Returns the number of bytes that were successfully read, RESULT_ERROR if an error occurred or RESULT_TIMEOUT if a timeout occurred.

ssize_t filedescriptor::read | ( | char * | buffer,
|  | int32_t | sec,
|  | int32_t | usec
| ) |  |

Reads a character from the file descriptor into "buffer" with a timeout of "sec" seconds and "usec" microseconds. Returns the number of bytes that were successfully read, RESULT_ERROR if an error occurred or RESULT_TIMEOUT if a timeout occurred.

ssize_t filedescriptor::read | ( | bool * | buffer,
|  | int32_t | sec,
|  | int32_t | usec
| ) |  |

Reads a boolean value from the file descriptor into "buffer" with a timeout of "sec" seconds and "usec" microseconds. Returns the number of bytes that were successfully read, RESULT_ERROR if an error occurred or RESULT_TIMEOUT if a timeout occurred.

ssize_t filedescriptor::read | ( | unsigned char * | buffer,
|  | size_t | size,
|  | int32_t | sec,
|  | int32_t | usec
| ) |  |

Reads "size" unsigned characters from the file descriptor into "buffer" with a timeout of "sec" seconds and "usec" microseconds. Returns the number of bytes that were successfully read, RESULT_ERROR if an error occurred or RESULT_TIMEOUT if a timeout occurred.

ssize_t filedescriptor::read | ( | char * | buffer,
|  | size_t | size,
|  | int32_t | sec,
|  | int32_t | usec
| ) |  |

Reads "size" characters from the file descriptor into "buffer" with a timeout of "sec" seconds and "usec" microseconds. Returns the number of bytes that were successfully read, RESULT_ERROR if an error occurred or RESULT_TIMEOUT if a timeout occurred.

ssize_t filedescriptor::read | ( | void * | buf,
|  | size_t | size,
|  | int32_t | sec,
|  | int32_t | usec
| ) |  |

Reads "size" bytes from the file descriptor into "buffer" with a timeout of "sec" seconds and "usec" microseconds. Returns the number of bytes that were successfully read, RESULT_ERROR if an error occurred or RESULT_TIMEOUT if a timeout occurred.

ssize_t filedescriptor::read | ( | char ** | buffer,
|  | const char * | terminator,
|  | int32_t | sec,
|  | int32_t | usec
| ) |  |

Reads from the file desciptor into "buffer" until "terminator" is encountered with a timeout of "sec" seconds and "usec" microseconds.

Note that "buffer" is allocated internally and must be freed by the calling program.

Returns the number of bytes that were read or RESULT_ERROR if an error occurred.

ssize_t filedescriptor::read | ( | char ** | buffer,
|  | const char * | terminator,
|  | size_t | maxbytes,
|  | int32_t | sec,
|  | int32_t | usec
| ) |  |

Reads from the file desciptor into "buffer" until "terminator" is encountered with a timeout of "sec" seconds and "usec" microseconds.

Note that "buffer" is allocated internally and must be freed by the calling program.

Returns the number of bytes that were read, RESULT_ERROR if an error occurred or RESULT_MAX if maxbytes were read before the terminator was encountered.

Setting maxbytes to 0 disables it.

ssize_t filedescriptor::read | ( | char ** | buffer,
|  | const char * | terminator,
|  | size_t | maxbytes,
|  | char | escapechar,
|  | int32_t | sec,
|  | int32_t | usec
| ) |  |

Reads from the file desciptor into "buffer" until "terminator" is encountered, using "escapechar" as an escape character, with a timeout of "sec" seconds and "usec" microseconds.

Note that "buffer" is allocated internally and must be freed by the calling program.

Setting "escapechar" to '\0' disables it.

Returns the number of bytes that were read, RESULT_ERROR if an error occurred or RESULT_MAX if maxbytes were read before the terminator was encountered.

Setting maxbytes to 0 disables it.

virtual bool filedescriptor::receiveFileDescriptor | ( | int32_t * | fd | ) |
| virtual

Receives a file descriptor into buffer "fd". This is useful for receiving an open file descriptor passed from another process over a unix socket, for example.

virtual bool filedescriptor::receiveSocket | ( | int32_t * | sock | ) |
| virtual

Receives a socket into buffer "sock". This is useful for receiving an open file descriptor passed from another process over a unix socket, for example.

void filedescriptor::retryInterruptedFcntl | ( |  | ) |

Causes fcntl operations to be automatically retried if interrupted by a signal. This is the default behavior. Otherwise, if a fcntl is occurring and a signal interrupts it, the fcntl fails, the system error is set to EINTR and the fcntl must be retried.

void filedescriptor::retryInterruptedIoctl | ( |  | ) |

Causes ioctl operations to be automatically retried if interrupted by a signal. This is the default behavior. Otherwise, if a ioctl is occurring and a signal interrupts it, the ioctl fails, the system error is set to EINTR and the ioctl must be retried.

void filedescriptor::retryInterruptedReads | ( |  | ) |

Causes reads to automatically retry if interrupted by a signal. By default, if a read is occurring and a signal interrupts it, the read fails, the system error is set to EINTR and the read must be retried.

void filedescriptor::retryInterruptedWaits | ( |  | ) |

Causes wait operations to be automatically retried if interrupted by a signal. This is the default behavior. Otherwise, if a wait is occurring and a signal interrupts it, the wait fails, the system error is set to EINTR and the wait must be retried.

void filedescriptor::retryInterruptedWrites | ( |  | ) |

Causes writes to automatically retry if interrupted by a signal. By default, if a write is occurring and a signal interrupts it, the write fails, the system error is set to EINTR and the write must be retried.

void filedescriptor::safePrint | ( | unsigned char | c | ) |

Prints "c" to the filedescriptor, however if "c" is non-printing character then it is printed as a hex value of the format: (0x0a). Carriage returns, line feeds and tabs are printed as
, and .

void filedescriptor::safePrint | ( | const unsigned char * | str | ) |

Prints "str" to the filedescriptor, however all non-printing characters are printed as hex values of the format: (0x0a) and carriage returns, line feeds and tabs are printed as
, and .

void filedescriptor::safePrint | ( | const unsigned char * | str,
|  | int32_t | length
| ) |  |

Prints "length" characters of "str" to the filedescriptor, however all non-printing characters are printed as hex values of the format: (0x0a) and carriage returns, line feeds and tabs are printed as
, and .

void filedescriptor::safePrint | ( | char | c | ) |

Prints "c" to the filedescriptor, however if "c" is non-printing character then it is printed as a hex value of the format: (0x0a). Carriage returns, line feeds and tabs are printed as
, and .

void filedescriptor::safePrint | ( | const char * | str | ) |

Prints "str" to the filedescriptor, however all non-printing characters are printed as hex values of the format: (0x0a) and carriage returns, line feeds and tabs are printed as
, and .

void filedescriptor::safePrint | ( | const char * | str,
|  | int32_t | length
| ) |  |

Prints "length" characters of "str" to the filedescriptor, however all non-printing characters are printed as hex values of the format: (0x0a) and carriage returns, line feeds and tabs are printed as
, and .

void filedescriptor::setFileDescriptor | ( | int32_t | filedesc | ) |

Sets the file descriptor associated with the class to "filedesc".

bool filedescriptor::setReadBufferSize | ( | ssize_t | size | ) | const

If an application does many small reads, the overhead of all of those system calls can slow the application down substantially. To address that issue, the filedescriptor class can create a read buffer and attempt to keep it full. When the first read is attempted, it will attempt to read "size" bytes into the buffer and only return the number of bytes specified in the read. Subsequent reads will just return data from the buffer without doing additional system calls unless the buffer is empty.

Do not confuse this buffer with the tcp read buffer. The tcp read buffer resides in kernel space, is populated by the read() system call in an analagous manner and is used to minimize network latency, not application latency due to system calls. This buffer is in user space and populated in the manner described above.

This method sets the read buffer size to "size" bytes and returns true on success and false on failure.

void filedescriptor::setSecurityContext | ( | securitycontext * | ctx | ) |

Associates a securitycontext "ctx" with the filedescriptor. To remove the current context, pass in a NULL for "ctx".

bool filedescriptor::setTcpReadBufferSize | ( | int32_t | size | ) |

Sets the size of the kernel's TCP read buffer to "size" bytes. This is only useful for TCP socket file descriptors. Returns true on success and false on failure.

bool filedescriptor::setTcpWriteBufferSize | ( | int32_t | size | ) |

Sets the size of the kernel's TCP write buffer to "size" bytes. This is only useful for TCP socket file descriptors. Returns true on success and false on failure.

bool filedescriptor::setWriteBufferSize | ( | ssize_t | size | ) | const

If an application does many small writes, the overhead of all of those system calls can slow the application down substantially. To address that issue, the filedescriptor class can buffer data passed in to any of it's write() methods and only make system calls when the buffer is full or when it's flushed manually. Note that when using buffered writes, no data is actually written to the file descriptor until the buffer is full or until it's flushed manually.

Do not confuse this buffer with the tcp write buffer. The tcp write buffer resides in kernel space, is populated by the write() system call and is used to minimize network latency, not application latency due to system calls. This buffer is in user space and populated prior to the write() system call.

This method sets the write buffer size to "size" bytes. A size of 0 means not to buffer writes at all.

Returns true on success and false on failure.

virtual bool filedescriptor::supportsBlockingNonBlockingModes | ( |  | ) |
| virtual

Returns true if the client socket supports blocking/nonblocking modes and false otherwise.

Reimplemented in socketserver, and socketclient.

void filedescriptor::translateByteOrder | ( |  | ) |

Translate integers from native byte order to network byte order during writes and vice-versa during reads. By default, no translation is done.

virtual bool filedescriptor::useBlockingMode | ( |  | ) | const
| virtual

Puts the file descriptor in blocking mode. Returns true on success and false on failure.

Reimplemented in socketserver, and socketclient.

bool filedescriptor::useNaglesAlgorithm | ( |  | ) |

Causes small write()'s to be collected up and sent together when either the kernel's write buffer is full or when a maximum of 0.2 seconds has gone by. (enable Nagle's algorithm)

This is the default.

Returns true on success and false on failure.

virtual bool filedescriptor::useNonBlockingMode | ( |  | ) | const
| virtual

Puts the file descriptor in non-blocking mode. Returns true on success and false on failure.

Reimplemented in socketserver, and socketclient.

int32_t filedescriptor::waitForNonBlockingRead | ( | int32_t | sec,
|  | int32_t | usec
| ) |  | const

Causes the application to wait until a read() will proceed without blocking or until "sec" seconds and "usec" microseconds have elapsed.

Entering -1 for either parameter causes the method to wait indefinitely.

Entering 0 for both parameters causes the method to fall through immediately unless a data is immediately available.

Returns RESULT_ERROR on error, RESULT_TIMEOUT on timeout and otherwise returns the number of file descriptors that are ready to be read from.

This will usually be 1, indicating that the file descriptor represented by the class is ready to be read from.

int32_t filedescriptor::waitForNonBlockingWrite | ( | int32_t | sec,
|  | int32_t | usec
| ) |  | const

Causes the application to wait until a write() will proceed without blocking or until "sec" seconds and "usec" microseconds have elapsed.

Entering -1 for either parameter causes the method to wait indefinitely.

Entering 0 for both parameters causes the method to fall through immediately unless a data is immediately available.

Returns RESULT_ERROR on error, RESULT_TIMEOUT on timeout and otherwise returns the number of file descriptors that are ready to be written to.

This will usually be 1, indicating that the file descriptor represented by the class is ready to be written to.

ssize_t filedescriptor::write | ( | uint16_t | number | ) | const

Writes "number" to the file descriptor. Returns the number of bytes that were successfully written or RESULT_ERROR if an error occurred.

ssize_t filedescriptor::write | ( | uint32_t | number | ) | const

Writes "number" to the file descriptor. Returns the number of bytes that were successfully written or RESULT_ERROR if an error occurred.

ssize_t filedescriptor::write | ( | uint64_t | number | ) | const

Writes "number" to the file descriptor. Returns the number of bytes that were successfully written or RESULT_ERROR if an error occurred.

ssize_t filedescriptor::write | ( | int16_t | number | ) | const

Writes "number" to the file descriptor. Returns the number of bytes that were successfully written or RESULT_ERROR if an error occurred.

ssize_t filedescriptor::write | ( | int32_t | number | ) | const

Writes "number" to the file descriptor. Returns the number of bytes that were successfully written or RESULT_ERROR if an error occurred.

ssize_t filedescriptor::write | ( | int64_t | number | ) | const

Writes "number" to the file descriptor. Returns the number of bytes that were successfully written or RESULT_ERROR if an error occurred.

ssize_t filedescriptor::write | ( | float | number | ) | const

Writes "number" to the file descriptor. Returns the number of bytes that were successfully written or RESULT_ERROR if an error occurred.

ssize_t filedescriptor::write | ( | double | number | ) | const

Writes "number" to the file descriptor. Returns the number of bytes that were successfully written or RESULT_ERROR if an error occurred.

ssize_t filedescriptor::write | ( | unsigned char | character | ) | const

Writes "character" to the file descriptor. Returns the number of bytes that were successfully written or RESULT_ERROR if an error occurred.

ssize_t filedescriptor::write | ( | char | character | ) | const

Writes "character" to the file descriptor. Returns the number of bytes that were successfully written or RESULT_ERROR if an error occurred.

ssize_t filedescriptor::write | ( | bool | value | ) | const

Writes "value" to the file descriptor. Returns the number of bytes that were successfully written or RESULT_ERROR if an error occurred.

ssize_t filedescriptor::write | ( | const unsigned char * | string | ) | const

Writes NULL-terminated "string" to the file descriptor. Returns the number of bytes that were successfully written or RESULT_ERROR if an error occurred.

ssize_t filedescriptor::write | ( | const char * | string | ) | const

Writes NULL-terminated "string" to the file descriptor. Returns the number of bytes that were successfully written or RESULT_ERROR if an error occurred.

ssize_t filedescriptor::write | ( | const unsigned char * | string,
|  | size_t | size
| ) |  | const

Writes "size" bytes of "string" to the file descriptor. Returns the number of bytes that were successfully written or RESULT_ERROR if an error occurred. Note that it is possible to write beyond the string's NULL terminator using this method.

ssize_t filedescriptor::write | ( | const char * | string,
|  | size_t | size
| ) |  | const

Writes "size" bytes of "string" to the file descriptor. Returns the number of bytes that were successfully written or RESULT_ERROR if an error occurred. Note that it is possible to write beyond the string's NULL terminator using this method.

ssize_t filedescriptor::write | ( | const void * | buffer,
|  | size_t | size
| ) |  | const

Writes "size" bytes of "buffer" to the file descriptor. Returns the number of bytes that were successfully written or RESULT_ERROR if an error occurred.

ssize_t filedescriptor::write | ( | uint16_t | number,
|  | int32_t | sec,
|  | int32_t | usec
| ) |  | const

Writes "number" to the file descriptor with a timeout of "sec" seconds and "usec" microseconds. Returns the number of bytes that were successfully written or RESULT_ERROR if an error occurred or RESULT_TIMEOUT if a timeout occurred.

ssize_t filedescriptor::write | ( | uint32_t | number,
|  | int32_t | sec,
|  | int32_t | usec
| ) |  | const

Writes "number" to the file descriptor with a timeout of "sec" seconds and "usec" microseconds. Returns the number of bytes that were successfully written or RESULT_ERROR if an error occurred or RESULT_TIMEOUT if a timeout occurred.

ssize_t filedescriptor::write | ( | uint64_t | number,
|  | int32_t | sec,
|  | int32_t | usec
| ) |  | const

Writes "number" to the file descriptor with a timeout of "sec" seconds and "usec" microseconds. Returns the number of bytes that were successfully written or RESULT_ERROR if an error occurred or RESULT_TIMEOUT if a timeout occurred.

ssize_t filedescriptor::write | ( | int16_t | number,
|  | int32_t | sec,
|  | int32_t | usec
| ) |  | const

Writes "number" to the file descriptor with a timeout of "sec" seconds and "usec" microseconds. Returns the number of bytes that were successfully written or RESULT_ERROR if an error occurred or RESULT_TIMEOUT if a timeout occurred.

ssize_t filedescriptor::write | ( | int32_t | number,
|  | int32_t | sec,
|  | int32_t | usec
| ) |  | const

Writes "number" to the file descriptor with a timeout of "sec" seconds and "usec" microseconds. Returns the number of bytes that were successfully written or RESULT_ERROR if an error occurred or RESULT_TIMEOUT if a timeout occurred.

ssize_t filedescriptor::write | ( | int64_t | number,
|  | int32_t | sec,
|  | int32_t | usec
| ) |  | const

Writes "number" to the file descriptor with a timeout of "sec" seconds and "usec" microseconds. Returns the number of bytes that were successfully written or RESULT_ERROR if an error occurred or RESULT_TIMEOUT if a timeout occurred.

ssize_t filedescriptor::write | ( | float | number,
|  | int32_t | sec,
|  | int32_t | usec
| ) |  | const

Writes "number" to the file descriptor with a timeout of "sec" seconds and "usec" microseconds. Returns the number of bytes that were successfully written or RESULT_ERROR if an error occurred or RESULT_TIMEOUT if a timeout occurred.

ssize_t filedescriptor::write | ( | double | number,
|  | int32_t | sec,
|  | int32_t | usec
| ) |  | const

Writes "number" to the file descriptor with a timeout of "sec" seconds and "usec" microseconds. Returns the number of bytes that were successfully written or RESULT_ERROR if an error occurred or RESULT_TIMEOUT if a timeout occurred.

ssize_t filedescriptor::write | ( | unsigned char | character,
|  | int32_t | sec,
|  | int32_t | usec
| ) |  | const

Writes "character" to the file descriptor with a timeout of "sec" seconds and "usec" microseconds. Returns the number of bytes that were successfully written or RESULT_ERROR if an error occurred or RESULT_TIMEOUT if a timeout occurred.

ssize_t filedescriptor::write | ( | char | character,
|  | int32_t | sec,
|  | int32_t | usec
| ) |  | const

Writes "character" to the file descriptor with a timeout of "sec" seconds and "usec" microseconds. Returns the number of bytes that were successfully written or RESULT_ERROR if an error occurred or RESULT_TIMEOUT if a timeout occurred.

ssize_t filedescriptor::write | ( | bool | value,
|  | int32_t | sec,
|  | int32_t | usec
| ) |  | const

Writes "value" to the file descriptor with a timeout of "sec" seconds and "usec" microseconds. Returns the number of bytes that were successfully written or RESULT_ERROR if an error occurred or RESULT_TIMEOUT if a timeout occurred.

ssize_t filedescriptor::write | ( | const unsigned char * | string,
|  | int32_t | sec,
|  | int32_t | usec
| ) |  | const

Writes NULL-terminated "string" to the file descriptor with a timeout of "sec" seconds and "usec" microseconds. Returns the number of bytes that were successfully written or RESULT_ERROR if an error occurred or RESULT_TIMEOUT if a timeout occurred.

ssize_t filedescriptor::write | ( | const char * | string,
|  | int32_t | sec,
|  | int32_t | usec
| ) |  | const

Writes NULL-terminated "string" to the file descriptor with a timeout of "sec" seconds and "usec" microseconds. Returns the number of bytes that were successfully written or RESULT_ERROR if an error occurred or RESULT_TIMEOUT if a timeout occurred.

ssize_t filedescriptor::write | ( | const unsigned char * | string,
|  | size_t | size,
|  | int32_t | sec,
|  | int32_t | usec
| ) |  | const

Writes "size" bytes of "string" to the file descriptor with a timeout of "sec" seconds and "usec" microseconds. Returns the number of bytes that were successfully written or RESULT_ERROR if an error occurred or RESULT_TIMEOUT if a timeout occurred. Note that it is possible to write beyond the string's NULL terminator using this method.

ssize_t filedescriptor::write | ( | const char * | string,
|  | size_t | size,
|  | int32_t | sec,
|  | int32_t | usec
| ) |  | const

Writes "size" bytes of "string" to the file descriptor with a timeout of "sec" seconds and "usec" microseconds. Returns the number of bytes that were successfully written or RESULT_ERROR if an error occurred or RESULT_TIMEOUT if a timeout occurred. Note that it is possible to write beyond the string's NULL terminator using this method.

ssize_t filedescriptor::write | ( | const void * | buffer,
|  | size_t | size,
|  | int32_t | sec,
|  | int32_t | usec
| ) |  | const

Writes "size" bytes of "buffer" to the file descriptor with a timeout of "sec" seconds and "usec" microseconds. Returns the number of bytes that were successfully written or RESULT_ERROR if an error occurred or RESULT_TIMEOUT if a timeout occurred.