Classes | Public Types | Public Member Functions | Private Types | Private Member Functions | Private Attributes | List of all members
roswrap::PollSet Class Reference

Manages a set of sockets being polled through the poll() function call. More...

#include <poll_set.h>

Classes

struct  SocketInfo
 

Public Types

typedef std::function< void(int)> SocketUpdateFunc
 

Public Member Functions

bool addEvents (int sock, int events)
 Add events to be polled on a socket. More...
 
bool addSocket (int sock, const SocketUpdateFunc &update_func, const TransportPtr &transport=TransportPtr())
 Add a socket. More...
 
bool delEvents (int sock, int events)
 Delete events to be polled on a socket. More...
 
bool delSocket (int sock)
 Delete a socket. More...
 
 PollSet ()
 
void signal ()
 Signal our poll() call to finish if it's blocked waiting (see the poll_timeout option for update()). More...
 
void update (int poll_timeout)
 Process all socket events. More...
 
 ~PollSet ()
 

Private Types

typedef std::map< int, SocketInfoM_SocketInfo
 
typedef std::vector< int > V_int
 

Private Member Functions

void createNativePollset ()
 Creates the native pollset for our sockets, if any have changed. More...
 
void onLocalPipeEvents (int events)
 Called when events have been triggered on our signal pipe. More...
 

Private Attributes

V_int just_deleted_
 
std::mutex just_deleted_mutex_
 
std::mutex signal_mutex_
 
signal_fd_t signal_pipe_ [2]
 
M_SocketInfo socket_info_
 
std::mutex socket_info_mutex_
 
bool sockets_changed_
 
std::vector< socket_pollfdufds_
 

Detailed Description

Manages a set of sockets being polled through the poll() function call.

PollSet provides thread-safe ways of adding and deleting sockets, as well as adding and deleting events.

Definition at line 58 of file poll_set.h.

Member Typedef Documentation

◆ M_SocketInfo

typedef std::map<int, SocketInfo> roswrap::PollSet::M_SocketInfo
private

Definition at line 138 of file poll_set.h.

◆ SocketUpdateFunc

typedef std::function<void(int)> roswrap::PollSet::SocketUpdateFunc

Definition at line 64 of file poll_set.h.

◆ V_int

typedef std::vector<int> roswrap::PollSet::V_int
private

Definition at line 144 of file poll_set.h.

Constructor & Destructor Documentation

◆ PollSet()

roswrap::PollSet::PollSet ( )

◆ ~PollSet()

roswrap::PollSet::~PollSet ( )

Member Function Documentation

◆ addEvents()

bool roswrap::PollSet::addEvents ( int  sock,
int  events 
)

Add events to be polled on a socket.

addEvents() may be called from any thread.

Parameters
sockThe socket to add events to
eventsThe events to add

◆ addSocket()

bool roswrap::PollSet::addSocket ( int  sock,
const SocketUpdateFunc update_func,
const TransportPtr transport = TransportPtr() 
)

Add a socket.

addSocket() may be called from any thread.

Parameters
sockThe socket to add
update_funcThe function to call when a socket has events
transportThe (optional) transport associated with this socket. Mainly used to prevent the transport from being deleted while we're calling the update function

◆ createNativePollset()

void roswrap::PollSet::createNativePollset ( )
private

Creates the native pollset for our sockets, if any have changed.

◆ delEvents()

bool roswrap::PollSet::delEvents ( int  sock,
int  events 
)

Delete events to be polled on a socket.

delEvents() may be called from any thread.

Parameters
sockThe socket to delete events from
eventsThe events to delete

◆ delSocket()

bool roswrap::PollSet::delSocket ( int  sock)

Delete a socket.

delSocket() may be called from any thread.

Parameters
sockThe socket to delete

◆ onLocalPipeEvents()

void roswrap::PollSet::onLocalPipeEvents ( int  events)
private

Called when events have been triggered on our signal pipe.

◆ signal()

void roswrap::PollSet::signal ( )

Signal our poll() call to finish if it's blocked waiting (see the poll_timeout option for update()).

◆ update()

void roswrap::PollSet::update ( int  poll_timeout)

Process all socket events.

This function will actually call poll() on the available sockets, and allow them to do their processing.

update() may only be called from one thread at a time

Parameters
poll_timeoutThe time, in milliseconds, for the poll() call to timeout after if there are no events. Note that this does not provide an upper bound for the entire function, just the call to poll()

Member Data Documentation

◆ just_deleted_

V_int roswrap::PollSet::just_deleted_
private

Definition at line 145 of file poll_set.h.

◆ just_deleted_mutex_

std::mutex roswrap::PollSet::just_deleted_mutex_
private

Definition at line 143 of file poll_set.h.

◆ signal_mutex_

std::mutex roswrap::PollSet::signal_mutex_
private

Definition at line 149 of file poll_set.h.

◆ signal_pipe_

signal_fd_t roswrap::PollSet::signal_pipe_[2]
private

Definition at line 150 of file poll_set.h.

◆ socket_info_

M_SocketInfo roswrap::PollSet::socket_info_
private

Definition at line 139 of file poll_set.h.

◆ socket_info_mutex_

std::mutex roswrap::PollSet::socket_info_mutex_
private

Definition at line 140 of file poll_set.h.

◆ sockets_changed_

bool roswrap::PollSet::sockets_changed_
private

Definition at line 141 of file poll_set.h.

◆ ufds_

std::vector<socket_pollfd> roswrap::PollSet::ufds_
private

Definition at line 147 of file poll_set.h.


The documentation for this class was generated from the following file:


sick_scan_xd
Author(s): Michael Lehning , Jochen Sprickerhof , Martin Günther
autogenerated on Fri Oct 25 2024 02:47:15