Bond's TCP Library  1.0
Bond's TCP Client/Server Library
tcp::EPoll Class Reference

Encapsulates the EPoll interface. More...

#include <tcpsocket.h>

Public Member Functions

 EPoll ()
 Constructor.
 
 ~EPoll ()
 Destructor.
 
void poll (int timeout)
 Call poll() regularly to respond to network events. More...
 

Friends

class Socket
 

Detailed Description

Encapsulates the EPoll interface.

Applications need to provide an epoll object for each thread in the application that uses sockets. These threads then call EPoll.poll(100) at regular intervals to check for and respond to network events.

Appropriate events are added/remove from the epoll event list when a tcp::Socket is created/destroyed. See the protected tcp::Socket.setEvents() method if you need to change which events a socket listens to.

When incoming events are recieved, they are automatically dispatched to the virtual Socket.handleEvents() method.

Definition at line 72 of file tcpsocket.h.

Member Function Documentation

◆ poll()

void tcp::EPoll::poll ( int  timeout)

Call poll() regularly to respond to network events.

Parameters
timeoutNumber of ms to wait for an event. Can be zero.

Definition at line 74 of file tcpsocket.cpp.

75 {
76  int nfds = epoll_wait(handle_,events,MAX_EVENTS,timeout);
77  if (nfds == -1) {
78  if (errno != EINTR)
79  error("epoll_wait",strerror(errno));
80  } else {
81  for (int n = 0; n < nfds; ++n) {
82  handleEvents(events[n].events,events[n].data.fd);
83  }
84  }
85 }
Here is the call graph for this function:

The documentation for this class was generated from the following files:
tcp::error
void error(string msg)
Send an error message to the log stream.
Definition: tcpsocket.cpp:18