TSDuck v3.44-4659
MPEG Transport Stream Toolkit
Loading...
Searching...
No Matches
ts::ReactiveUDPSocket Class Reference

UDP Socket for use in a Reactor environment. More...

#include <tsReactiveUDPSocket.h>

Inheritance diagram for ts::ReactiveUDPSocket:
Collaboration diagram for ts::ReactiveUDPSocket:

Public Member Functions

 ReactiveUDPSocket (Reactor &reactor, UDPSocket &socket)
 Constructor.
 
virtual ~ReactiveUDPSocket () override
 Destructor.
 
void cancelSendReceive (bool silent=false)
 Cancel any pending send or receive operation on this socket.
 
Reactorreactor ()
 Get a reference to the associated reactor.
 
UDPSocketsocket ()
 Get a reference to the associated socket.
 
bool startClose (ReactiveUDPHandlerInterface *handler, bool silent=false)
 Start closing the socket.
 
bool startReceive (ReactiveUDPHandlerInterface *handler, size_t max_message_size=IP_MAX_PACKET_SIZE)
 Start the operation of receiving messages from the socket.
 
bool startSend (ReactiveUDPHandlerInterface *handler, const void *data, size_t size)
 Start the operation of sending a message to the default destination address and port.
 
bool startSend (ReactiveUDPHandlerInterface *handler, const void *data, size_t size, const IPSocketAddress &destination)
 Start the operation of sending a message to a destination address and port.
 

Detailed Description

UDP Socket for use in a Reactor environment.

The class ReactiveUDPSocket is a wrapper around UDPSocket to handle reactive I/O.

The actual socket is a separate object. It is initialized and configured by the application. The application shall not directly call send(), receive(), or close() on this socket and delegate these operations to startSend(), startReceive(), and startClose in class ReactiveUDPSocket.

Constructor & Destructor Documentation

◆ ReactiveUDPSocket()

ts::ReactiveUDPSocket::ReactiveUDPSocket ( Reactor reactor,
UDPSocket socket 
)

Constructor.

Parameters
[in,out]reactorAssociated reactor. The reactor object must remain valid as long as this object is valid.
[in,out]socketAssociated socket. The socket object must remain valid as long as this object is valid. The ReactiveUDPSocket must be initialized before the socket is opened.

Member Function Documentation

◆ reactor()

Reactor & ts::ReactiveUDPSocket::reactor ( )
inline

Get a reference to the associated reactor.

Returns
A reference to the associated reactor.

◆ socket()

UDPSocket & ts::ReactiveUDPSocket::socket ( )
inline

Get a reference to the associated socket.

Returns
A reference to the associated socket.

◆ startSend() [1/2]

bool ts::ReactiveUDPSocket::startSend ( ReactiveUDPHandlerInterface handler,
const void *  data,
size_t  size,
const IPSocketAddress destination 
)

Start the operation of sending a message to a destination address and port.

Parameters
[in]dataAddress of the message to send. The corresponding memory area must remain valid until the completion or cancelation of the send operation.
[in]sizeSize in bytes of the message to send.
[in]destinationSocket address of the destination. Both address and port are mandatory in the socket address, they cannot be set to IPAddress::AnyAddress4 or IPSocketAddress::AnyPort.
[in]handlerHandler class to call when the send operation completes. If nullptr, no handler is caller.
Returns
True on success, false on error. Success means that the I/O was successfully started. The final status of the I/O will be transmitted in the handler.

◆ startSend() [2/2]

bool ts::ReactiveUDPSocket::startSend ( ReactiveUDPHandlerInterface handler,
const void *  data,
size_t  size 
)
inline

Start the operation of sending a message to the default destination address and port.

Parameters
[in]dataAddress of the message to send. The corresponding memory area must remain valid until the completion or cancelation of the send operation.
[in]sizeSize in bytes of the message to send.
[in]handlerHandler class to call when the send operation completes. If nullptr, no handler is caller.
Returns
True on success, false on error. Success means that the I/O was successfully started. The final status of the I/O will be transmitted in the handler.

◆ startReceive()

bool ts::ReactiveUDPSocket::startReceive ( ReactiveUDPHandlerInterface handler,
size_t  max_message_size = IP_MAX_PACKET_SIZE 
)

Start the operation of receiving messages from the socket.

Parameters
[in]handlerHandler class to call each time a message is received. Cannot be null. If a previous handler was registered, it is replaced.
[in]max_message_sizeMaximum incoming message size. Used as size of internal reception buffer. The default is the maximum IP packet size.
Returns
True on success, false on error. Success means that the I/O was successfully started. The final status of the I/O will be transmitted in the handler.

◆ cancelSendReceive()

void ts::ReactiveUDPSocket::cancelSendReceive ( bool  silent = false)

Cancel any pending send or receive operation on this socket.

If a repeated reception operation is in progress, the repetition is canceled as well.

Parameters
[in]silentIf true, do not report errors through the logger.

◆ startClose()

bool ts::ReactiveUDPSocket::startClose ( ReactiveUDPHandlerInterface handler,
bool  silent = false 
)

Start closing the socket.

Pending asynchronous operations are canceled. The actual cancelation will take place later. In the meantime, the user's data buffers for these pending operations are busy and shall not be destroyed / deallocated by the application. The close operation terminates when the handler handleUDPClosed() is invoked. At this point, no more operation is pending and the application may get rid of data buffers.

Parameters
[in]handlerHandler class to call when the close operation completes.
[in]silentIf true, do not report errors through the logger.
Returns
True on success, false on error.

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