libsocket
Classes | Namespaces | Functions
select.hpp File Reference

Contains the class selectset which provides a neat interface for watching several sockets. More...

Go to the source code of this file.

Classes

class  libsocket::selectset< SocketT >
 selectset provides a simple abstraction over – contrary to its name – poll(2). More...
 

Namespaces

 libsocket
 Contains libsocket elements.
 

Functions

int libsocket::highestfd (const std::vector< int > &v)
 Utility function to find the highest number in a vector (typically, the highest file descriptor) More...
 

Detailed Description

Contains the class selectset which provides a neat interface for watching several sockets.

The class selectset implements a wrapper for the syscall poll() (formerly select()) which allows to accept connections on more than one socket or communicate with multiple clients without multithreading.

New sockets may be added with add_fd(), accepting a child class of libsocket::socket.

When all sockets are added, the poll() call can be triggered by calling wait(). This function returns a pair of vector<int>s, the first with the sockets ready for reading and the second containing the sockets ready for writing.

This is a template class; use the appropriate socket class as template argument. If you want to select on several different sockets (e.g. an INET server and an INET client), use some superclass and dynamic_cast to cast the pointers returned by wait().

Definition in file select.hpp.