unixsocketserver Class Reference

Inherits socketserver, and unixsocketutil.

## Public Member Functions

| unixsocketserver ()
| unixsocketserver (const unixsocketserver &u)
unixsocketserver & | operator= (const unixsocketserver &u)
virtual | ~unixsocketserver ()
bool | listen (const char *filename, mode_t mask, int32_t backlog)
bool | initialize (const char *filename, mode_t mask)
bool | bind ()
bool | listen (int32_t backlog)
filedescriptor * | accept ()
bool | close ()
Public Member Functions inherited from socketserver
| socketserver ()
| socketserver (const socketserver &s)
socketserver & | operator= (const socketserver &s)
virtual | ~socketserver ()
virtual bool | supportsBlockingNonBlockingModes ()
virtual bool | useNonBlockingMode () const
virtual bool | useBlockingMode () const
virtual bool | isUsingNonBlockingMode () const
virtual int32_t | ioCtl (int32_t command, void *arg) const
bool | lingerOnClose (int32_t timeout)
bool | dontLingerOnClose ()
bool | reuseAddresses ()
bool | dontReuseAddresses ()
Public Member Functions inherited from server
| server ()
| server (const server &s)
server & | operator= (const server &s)
virtual | ~server ()
Public Member Functions inherited from filedescriptor
| filedescriptor ()
| filedescriptor (const filedescriptor &f)
filedescriptor & | operator= (const filedescriptor &f)
virtual | ~filedescriptor ()
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 ()
ssize_t | write (uint16_t number)
ssize_t | write (uint32_t number)
ssize_t | write (uint64_t number)
ssize_t | write (int16_t number)
ssize_t | write (int32_t number)
ssize_t | write (int64_t number)
ssize_t | write (float number)
ssize_t | write (double number)
ssize_t | write (unsigned char character)
ssize_t | write (char character)
ssize_t | write (bool value)
ssize_t | write (const unsigned char *string)
ssize_t | write (const char *string)
ssize_t | write (const unsigned char *string, size_t size)
ssize_t | write (const char *string, size_t length)
ssize_t | write (const void *buffer, size_t size)
ssize_t | write (uint16_t number, int32_t sec, int32_t usec)
ssize_t | write (uint32_t number, int32_t sec, int32_t usec)
ssize_t | write (uint64_t number, int32_t sec, int32_t usec)
ssize_t | write (int16_t number, int32_t sec, int32_t usec)
ssize_t | write (int32_t number, int32_t sec, int32_t usec)
ssize_t | write (int64_t number, int32_t sec, int32_t usec)
ssize_t | write (float number, int32_t sec, int32_t usec)
ssize_t | write (double number, int32_t sec, int32_t usec)
ssize_t | write (unsigned char character, int32_t sec, int32_t usec)
ssize_t | write (char character, int32_t sec, int32_t usec)
ssize_t | write (bool value, int32_t sec, int32_t usec)
ssize_t | write (const unsigned char *string, int32_t sec, int32_t usec)
ssize_t | write (const char *string, int32_t sec, int32_t usec)
ssize_t | write (const unsigned char *string, size_t size, int32_t sec, int32_t usec)
ssize_t | write (const char *string, size_t size, int32_t sec, int32_t usec)
ssize_t | write (const void *buffer, size_t size, int32_t sec, int32_t usec)
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 (const 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 length)
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
bool | useNaglesAlgorithm ()
bool | dontUseNaglesAlgorithm ()
bool | setSocketWriteBufferSize (int32_t size)
bool | getSocketWriteBufferSize (int32_t *size)
bool | setSocketReadBufferSize (int32_t size)
bool | getSocketReadBufferSize (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)
bool | setReadBufferSize (ssize_t size) const
bool | closeOnExec ()
bool | dontCloseOnExec ()
bool | getCloseOnExec ()

## Additional Inherited Members

Static Public Member Functions inherited from filedescriptor
static bool | createPipe (filedescriptor *readfd, filedescriptor *writefd)
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)
static uint16_t | hostToLittleEndian (uint16_t value)
static uint32_t | hostToLittleEndian (uint32_t value)
static uint64_t | hostToLittleEndian (uint64_t value)
static uint16_t | littleEndianToHost (uint16_t value)
static uint32_t | littleEndianToHost (uint32_t value)
static uint64_t | littleEndianToHost (uint64_t value)

## Detailed Description

The unixsocketserver class allows you to write programs that can talk to other programs on the same machine over TCP stream sockets.

Inet sockets (see the inetsocketserver class) can be used by clients and servers on the same machine as well, but Unix sockets generally perform better.

Some platforms (line Windows) don't support Unix sockets. For those platforms, Unix sockets are simulated using Inet sockets on localhost by translating the socket filename to a port. See unixsocketutil::filenameToPort() for details.

The unixsocketserver class provides methods for setting up sockets and accepting client connections. Its ultimate parent class: transport, provides methods for reading and writing data and closing connections. An immediate parent class: unixsocket provides methods for passing file descriptors between connected instances of unixservertsocket's and unixsocketclient's.

If you need to listen on more than 1 socket at a time, you should use the unixsocketserver class (and possibly the unixsocketserver class) in conjunction with the listener class.

## Constructor & Destructor Documentation

## unixsocketserver() [1/2]

unixsocketserver::unixsocketserver | ( |  | ) |

Creates an instance of the unixsocketserver class.

## unixsocketserver() [2/2]

unixsocketserver::unixsocketserver | ( | const unixsocketserver & | u | ) |

Creates an instance of the unixsocketserver class that is a copy of "u".

## ~unixsocketserver()

virtual unixsocketserver::~unixsocketserver | ( |  | ) |

virtual

Deletes this instance of the unixsocketserver class.

## Member Function Documentation

## accept()

filedescriptor* unixsocketserver::accept | ( |  | ) |

virtual

Removes the client connection from the queue and associates a new socket with that connection. Communication with the client may be done over this new socket.

Returns an inetsocket on success and NULL on failure.

Reimplemented from server.

## bind()

bool unixsocketserver::bind | ( |  | ) |

virtual

Associates the socket with an address.

Returns true on success and false on failure.

Reimplemented from server.

## close()

bool unixsocketserver::close | ( |  | ) |

virtual

Closes the socket. Returns true on success and false on failure.

Reimplemented from filedescriptor.

## initialize()

bool unixsocketserver::initialize | ( | const char * | filename,
|  | mode_t | mask
| ) |  |

Creates the actual socket and initializes the class to use "filename" when bind() is called. The permissions on "filename" will be set using umask "mask".

Returns true on success and false on failure.

## listen() [1/2]

bool unixsocketserver::listen | ( | const char * | filename,
|  | mode_t | mask,
|  | int32_t | backlog
| ) |  |

Convenience method that calls initialize(), bind() and listen(). If you need to set socket options or do anything else special between those discrete steps then you should use the methods individually.

Listen on "filename" and allow "backlog" connections to pile up before refusing them. Set the permissions on "filename" using umask "mask".

Returns true on success and false on failure.

## listen() [2/2]

bool unixsocketserver::listen | ( | int32_t | backlog | ) |

virtual

Waits until a client connects then places that connection in queue. Up to "backlog" connections may be queued before future conenctions are refused.

Returns true on success and false on failure.

Reimplemented from socketserver.

## operator=()

unixsocketserver& unixsocketserver::operator= | ( | const unixsocketserver & | u | ) |

Makes this instance of the unixsocketserver class identical to "u".