Woman, Life, Freedom


Async BSD Sockets Library
Library protected and public interface header documentation
AsyncBsdSocketLib::Poller Class Reference

Communicator poller. More...

#include <poller.h>

Public Member Functions

 Poller ()
 Constructor. More...
 
bool TryAddListener (TcpListener *tcpListener, std::function< void()> callback)
 Try to add a TCP listener to the poller. More...
 
bool TryAddSender (Communicator *communicator, std::function< void()> callback)
 Try to add a sender to the poller. More...
 
bool TryAddReceiver (Communicator *communicator, std::function< void()> callback)
 Try to add a receiver to the poller. More...
 
bool TryRemoveListener (TcpListener *tcpListener)
 Try to remove the TCP listener from the poller. More...
 
bool TryRemoveSender (Communicator *communicator)
 Try to remove the sender from the poller. More...
 
bool TryRemoveReceiver (Communicator *communicator)
 Try to remove the receiver from the poller. More...
 
bool TryPoll (int timeout=0) const
 Try to perform an explicit polling over all the added communicators. More...
 

Detailed Description

Communicator poller.

Constructor & Destructor Documentation

◆ Poller()

AsyncBsdSocketLib::Poller::Poller ( )

Constructor.

Exceptions
std::runtime_exceptionThrows when the poller creation failed

Member Function Documentation

◆ TryAddListener()

bool AsyncBsdSocketLib::Poller::TryAddListener ( TcpListener tcpListener,
std::function< void()>  callback 
)

Try to add a TCP listener to the poller.

Parameters
tcpListenerTCP listener socket
callbackCallback to be fired when the socket is ready to accept a client
Returns
True if the socket is added successfully to the poller; otherwise false
Remarks
The function call is thread-safe.

◆ TryAddReceiver()

bool AsyncBsdSocketLib::Poller::TryAddReceiver ( Communicator communicator,
std::function< void()>  callback 
)

Try to add a receiver to the poller.

Parameters
communicatorReceiver communicator
callbackCallback to be fired when the communicator is ready receive data
Returns
True if the communicator is added successfully to the poller; otherwise false
Remarks
The function call is thread-safe.

◆ TryAddSender()

bool AsyncBsdSocketLib::Poller::TryAddSender ( Communicator communicator,
std::function< void()>  callback 
)

Try to add a sender to the poller.

Parameters
communicatorSender communicator
callbackCallback to be fired when the communicator is ready to send data
Returns
True if the communicator is added successfully to the poller; otherwise false
Remarks
The function call is thread-safe.

◆ TryPoll()

bool AsyncBsdSocketLib::Poller::TryPoll ( int  timeout = 0) const

Try to perform an explicit polling over all the added communicators.

Parameters
timeoutPolling timeout in milliseconds
Returns
True if the polling was successful; otherwise false
Note
Zero timeout means immediate return from the polling
Timeout '-1' means polling indefinitely until an added communicator becomes available for IO

◆ TryRemoveListener()

bool AsyncBsdSocketLib::Poller::TryRemoveListener ( TcpListener tcpListener)

Try to remove the TCP listener from the poller.

Parameters
tcpListenerPreviously added TCP listener socket
Returns
True if the socket is removed successfully from the poller; otherwise false
Remarks
The function call is thread-safe.

◆ TryRemoveReceiver()

bool AsyncBsdSocketLib::Poller::TryRemoveReceiver ( Communicator communicator)

Try to remove the receiver from the poller.

Parameters
communicatorPreviously added receiver communicator
Returns
True if the communicator is removed successfully from the poller; otherwise false
Remarks
The function call is thread-safe.

◆ TryRemoveSender()

bool AsyncBsdSocketLib::Poller::TryRemoveSender ( Communicator communicator)

Try to remove the sender from the poller.

Parameters
communicatorPreviously added sender communicator
Returns
True if the communicator is removed successfully from the poller; otherwise false
Remarks
The function call is thread-safe.