template<typename SocketT>
class libsocket::epollset< SocketT >
Class abstracting calls to the epoll
API of Linux.
Being a template, this class needs to be initialized with a class. The choice is easy if you only have one type of socket to run epoll on; however, if you have (for example) an inet_stream
and an inet_stream_server
socket, you will need to use either socket
or inet_socket
as type parameter so the automatic upcasting works as intended.
Upon return of wait()
, you'll have to identify the sockets (using the address – this class is practically zero-copy) and cast them back with the help of dynamic_cast
.
Definition at line 69 of file epoll.hpp.
template<typename SocketT >
Wait for an event on any file descriptor.
- Parameters
-
timeout | (default: -1) Timeout, in milliseconds, after which to return if no event has occurred yet. -1 for indefinite waiting, 0 for non-blocking access. |
- Returns
- A pair of vectors containing pointers to SocketTs: (ready_for_reading[],ready_for_writing[]). With
r
being the returned pair, access the sockets using statements like r.first.size() > 0 ? r.first[0] : nullptr
or the like.
Hint: If you need to know what socket has been returned, maintain a mapping from socket pointers to some identification code. Using that mapping, you will be able to identify the sockets.
Hint 2: It never does any harm to check the length of the returned vector
s; with the included example http_epoll.cpp
, spurious empty-returning epoll calls could be observed. However, it is not clear if this is a bug in the libsocket implementation or usual behavior of epoll.
Definition at line 188 of file epoll.hpp.