Rudiments
|
Inherited by client, file, serialport, and server.
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 |
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, long sec, long usec) const |
ssize_t | write (uint32_t number, long sec, long usec) const |
ssize_t | write (uint64_t number, long sec, long usec) const |
ssize_t | write (int16_t number, long sec, long usec) const |
ssize_t | write (int32_t number, long sec, long usec) const |
ssize_t | write (int64_t number, long sec, long usec) const |
ssize_t | write (float number, long sec, long usec) const |
ssize_t | write (double number, long sec, long usec) const |
ssize_t | write (unsigned char character, long sec, long usec) const |
ssize_t | write (char character, long sec, long usec) const |
ssize_t | write (bool value, long sec, long usec) const |
ssize_t | write (const unsigned char *string, long sec, long usec) const |
ssize_t | write (const char *string, long sec, long usec) const |
ssize_t | write (const unsigned char *string, size_t size, long sec, long usec) const |
ssize_t | write (const char *string, size_t size, long sec, long usec) const |
ssize_t | write (const void *buffer, size_t size, long sec, long usec) const |
ssize_t | read (uint16_t *buffer) const |
ssize_t | read (uint32_t *buffer) const |
ssize_t | read (uint64_t *buffer) const |
ssize_t | read (int16_t *buffer) const |
ssize_t | read (int32_t *buffer) const |
ssize_t | read (int64_t *buffer) const |
ssize_t | read (float *buffer) const |
ssize_t | read (double *buffer) const |
ssize_t | read (unsigned char *buffer) const |
ssize_t | read (char *buffer) const |
ssize_t | read (bool *buffer) const |
ssize_t | read (unsigned char *buffer, size_t size) const |
ssize_t | read (char *buffer, size_t size) const |
ssize_t | read (void *buf, size_t size) const |
ssize_t | read (char **buffer, const char *terminator) const |
ssize_t | read (uint16_t *buffer, long sec, long usec) const |
ssize_t | read (uint32_t *buffer, long sec, long usec) const |
ssize_t | read (uint64_t *buffer, long sec, long usec) const |
ssize_t | read (int16_t *buffer, long sec, long usec) const |
ssize_t | read (int32_t *buffer, long sec, long usec) const |
ssize_t | read (int64_t *buffer, long sec, long usec) const |
ssize_t | read (float *buffer, long sec, long usec) const |
ssize_t | read (double *buffer, long sec, long usec) const |
ssize_t | read (unsigned char *buffer, long sec, long usec) const |
ssize_t | read (char *buffer, long sec, long usec) const |
ssize_t | read (bool *buffer, long sec, long usec) const |
ssize_t | read (unsigned char *buffer, size_t size, long sec, long usec) const |
ssize_t | read (char *buffer, size_t size, long sec, long usec) const |
ssize_t | read (void *buf, size_t size, long sec, long usec) const |
ssize_t | read (char **buffer, const char *terminator, long sec, long usec) const |
int32_t | waitForNonBlockingRead (long sec, long usec) const |
int32_t | waitForNonBlockingWrite (long sec, long 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 () |
void | useListener (listener *lstnr) |
void | dontUseListener () |
listener * | getListener () |
void | useListenerInsideReads () |
void | dontUseListenerInsideReads () |
void | useListenerInsideWrites () |
void | dontUseListenerInsideWrites () |
virtual bool | passFileDescriptor (int32_t fd) const |
virtual bool | receiveFileDescriptor (int32_t *fd) const |
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 (long sec, long 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) |
The filedescriptor class is a base class for other classes that utilize file descriptors.
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.
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 modemclient, and modemserver.
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.
void filedescriptor::dontUseListener | ( | ) |
By default, calls to waitForNonBlockingRead() and waitForNonBlockingWrite() will wait using the select() system call or similar.
This method causes the default behavior to be observed, even if useListener() was called previously.
void filedescriptor::dontUseListenerInsideReads | ( | ) |
Causes the listener set by a call to useListener() not to be used internally by the read() methods. See useListener().
void filedescriptor::dontUseListenerInsideWrites | ( | ) |
Causes the listener set by a call to useListener() not to be used internally by the write() methods. See useListener().
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 | ( | long | sec, |
long | 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.
listener* filedescriptor::getListener | ( | ) |
Returns the listener set previously by useListener() or NULL if none has been set.
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.
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 clientsocket, and serversocket.
virtual bool filedescriptor::isUsingNonBlockingMode | ( | ) | const [virtual] |
Returns true if the file descriptor is in non-blocking mode and false otherwise.
Reimplemented in clientsocket, and serversocket.
static uint64_t filedescriptor::netToHost | ( | uint64_t | value | ) | [static] |
Converts an unsigned 64-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 uint16_t filedescriptor::netToHost | ( | uint16_t | value | ) | [static] |
Converts an unsigned 16-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 | ) | const [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.
ssize_t filedescriptor::read | ( | double * | buffer, |
long | sec, | ||
long | usec | ||
) | const |
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, |
long | sec, | ||
long | usec | ||
) | const |
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, |
long | sec, | ||
long | usec | ||
) | const |
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, |
long | sec, | ||
long | usec | ||
) | const |
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, | ||
long | sec, | ||
long | usec | ||
) | const |
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, | ||
long | sec, | ||
long | usec | ||
) | const |
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, | ||
long | sec, | ||
long | usec | ||
) | const |
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 | ( | void * | buf, |
size_t | size | ||
) | const |
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, | ||
long | sec, | ||
long | usec | ||
) | const |
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 | ( | float * | buffer, |
long | sec, | ||
long | usec | ||
) | const |
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 | ( | uint16_t * | buffer | ) | const |
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 | ) | const |
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 | ) | const |
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 | ( | int64_t * | buffer, |
long | sec, | ||
long | usec | ||
) | const |
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 | ( | int16_t * | buffer | ) | const |
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 | ( | int16_t * | buffer, |
long | sec, | ||
long | usec | ||
) | const |
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 | ( | float * | buffer | ) | const |
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 | ( | int64_t * | buffer | ) | const |
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 | ( | double * | buffer | ) | const |
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 | ) | const |
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 | ( | bool * | buffer | ) | const |
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 | ( | char * | buffer | ) | const |
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 | ( | unsigned char * | buffer, |
size_t | size | ||
) | const |
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 | ||
) | const |
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 | ( | char ** | buffer, |
const char * | terminator | ||
) | const |
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 | ( | uint16_t * | buffer, |
long | sec, | ||
long | usec | ||
) | const |
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, |
long | sec, | ||
long | usec | ||
) | const |
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, |
long | sec, | ||
long | usec | ||
) | const |
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 | ( | int32_t * | buffer, |
long | sec, | ||
long | usec | ||
) | const |
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 | ( | int32_t * | buffer | ) | const |
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.
virtual bool filedescriptor::receiveFileDescriptor | ( | int32_t * | fd | ) | const [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.
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::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.
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 clientsocket, and serversocket.
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 clientsocket, and serversocket.
void filedescriptor::useListener | ( | listener * | lstnr | ) |
By default, calls to waitForNonBlockingRead() and waitForNonBlockingWrite() will wait using the select() system call or similar.
This method causes calls to waitForNonBlockingRead() and waitForNonBlockingWrite() to in turn call lstnr->waitForNonBlockingRead() or lstnr->waitForNonBlockingWrite() rather than using select() directly.
void filedescriptor::useListenerInsideReads | ( | ) |
Causes the listener set by a call to useListener() to be used internally by the read() methods. See useListener().
void filedescriptor::useListenerInsideWrites | ( | ) |
Causes the listener set by a call to useListener() to be be used internally by the write() methods. See useListener().
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 clientsocket, and serversocket.
int32_t filedescriptor::waitForNonBlockingRead | ( | long | sec, |
long | 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. However, if useListener() has been called, it may be greater than 1, indicating that a set of file descriptors that the listener is listening on are all ready to be read from.
int32_t filedescriptor::waitForNonBlockingWrite | ( | long | sec, |
long | 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. However, if useListener() has been called, it may be greater than 1, indicating that a set of file descriptors that the listener is listening on are all ready to be written to.
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, |
size_t | size, | ||
long | sec, | ||
long | 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 | ( | uint64_t | number, |
long | sec, | ||
long | 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, |
long | sec, | ||
long | 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, |
long | sec, | ||
long | 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 | ( | uint16_t | number, |
long | sec, | ||
long | 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 | ( | 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 | ( | 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 | ( | 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 | ( | 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 | ( | 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 | ( | 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 | ( | float | number, |
long | sec, | ||
long | 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 | ) | 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 | ( | const unsigned char * | string, |
long | sec, | ||
long | 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 | ( | 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 | ( | 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 | ( | double | number, |
long | sec, | ||
long | 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 | ) | 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 | ( | 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 | ( | 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 | ( | 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 | ( | int16_t | number, |
long | sec, | ||
long | 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 | ( | char | character, |
long | sec, | ||
long | 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 | ( | uint32_t | number, |
long | sec, | ||
long | 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 | ( | bool | value, |
long | sec, | ||
long | 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 | ( | unsigned char | character, |
long | sec, | ||
long | 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 | ( | const char * | string, |
long | sec, | ||
long | 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 | ( | 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 | ( | const char * | string, |
size_t | size, | ||
long | sec, | ||
long | 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 | ) | 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 void * | buffer, |
size_t | size, | ||
long | sec, | ||
long | 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.