UDP Socket for use in a Reactor environment.
More...
#include <tsReactiveUDPSocket.h>
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.
◆ ReactiveUDPSocket()
| ts::ReactiveUDPSocket::ReactiveUDPSocket |
( |
Reactor & |
reactor, |
|
|
UDPSocket & |
socket |
|
) |
| |
Constructor.
- Parameters
-
| [in,out] | reactor | Associated reactor. The reactor object must remain valid as long as this object is valid. |
| [in,out] | socket | Associated socket. The socket object must remain valid as long as this object is valid. The ReactiveUDPSocket must be initialized before the socket is opened. |
◆ 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]
Start the operation of sending a message to a destination address and port.
- Parameters
-
| [in] | data | Address of the message to send. The corresponding memory area must remain valid until the completion or cancelation of the send operation. |
| [in] | size | Size in bytes of the message to send. |
| [in] | destination | Socket 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] | handler | Handler 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]
Start the operation of sending a message to the default destination address and port.
- Parameters
-
| [in] | data | Address of the message to send. The corresponding memory area must remain valid until the completion or cancelation of the send operation. |
| [in] | size | Size in bytes of the message to send. |
| [in] | handler | Handler 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()
Start the operation of receiving messages from the socket.
- Parameters
-
| [in] | handler | Handler class to call each time a message is received. Cannot be null. If a previous handler was registered, it is replaced. |
| [in] | max_message_size | Maximum 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] | silent | If true, do not report errors through the logger. |
◆ startClose()
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] | handler | Handler class to call when the close operation completes. |
| [in] | silent | If 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: