TSDuck v3.40-3963
MPEG Transport Stream Toolkit
|
#include <tsUDPSocket.h>
Public Member Functions | |
UDPSocket (bool auto_open=false, Report &report=(ts::CerrReport::Instance())) | |
Constructor. | |
virtual | ~UDPSocket () override |
Destructor. | |
bool | addMembership (const IPv4Address &multicast, const IPv4Address &local, const IPv4Address &source=IPv4Address(), Report &report=(ts::CerrReport::Instance())) |
Join a multicast group. | |
bool | addMembershipAll (const IPv4Address &multicast, const IPv4Address &source=IPv4Address(), Report &report=(ts::CerrReport::Instance())) |
Join a multicast group. | |
bool | addMembershipDefault (const IPv4Address &multicast, const IPv4Address &source=IPv4Address(), Report &report=(ts::CerrReport::Instance())) |
Join a multicast group. | |
bool | bind (const IPv4SocketAddress &addr, Report &report=(ts::CerrReport::Instance())) |
Bind to a local address and port. | |
virtual bool | close (Report &report=(ts::CerrReport::Instance())) override |
Close the socket. | |
bool | dropMembership (Report &report=(ts::CerrReport::Instance())) |
Drop all multicast membership requests, including source-specific multicast. | |
IPv4SocketAddress | getDefaultDestination () const |
Get the default destination address and port for outgoing messages. | |
bool | getLocalAddress (IPv4SocketAddress &addr, Report &report=(ts::CerrReport::Instance())) |
Get local socket address. | |
SysSocketType | getSocket () const |
Get the underlying socket device handle (use with care). | |
bool | isOpen () const |
Check if socket is open. | |
virtual bool | open (Report &report=(ts::CerrReport::Instance())) override |
Open the socket. | |
virtual bool | receive (void *data, size_t max_size, size_t &ret_size, IPv4SocketAddress &sender, IPv4SocketAddress &destination, const AbortInterface *abort=nullptr, Report &report=(ts::CerrReport::Instance()), cn::microseconds *timestamp=nullptr) |
Receive a message. | |
bool | reusePort (bool reuse_port, Report &report=(ts::CerrReport::Instance())) |
Set the "reuse port" option. | |
virtual bool | send (const void *data, size_t size, const IPv4SocketAddress &destination, Report &report=(ts::CerrReport::Instance())) |
Send a message to a destination address and port. | |
virtual bool | send (const void *data, size_t size, Report &report=(ts::CerrReport::Instance())) |
Send a message to the default destination address and port. | |
bool | setBroadcast (bool on, Report &report=(ts::CerrReport::Instance())) |
Enable or disable the broadcast option. | |
bool | setBroadcastIfRequired (const IPv4Address destination, Report &report=(ts::CerrReport::Instance())) |
Enable or disable the broadcast option, based on an IP address. | |
bool | setDefaultDestination (const IPv4SocketAddress &addr, Report &report=(ts::CerrReport::Instance())) |
Set a default destination address and port for outgoing messages. | |
bool | setDefaultDestination (const UString &name, Report &report=(ts::CerrReport::Instance())) |
Set a default destination address and port for outgoing messages. | |
bool | setMulticastLoop (bool on, Report &report=(ts::CerrReport::Instance())) |
Set the multicast loop option. | |
bool | setOutgoingMulticast (const IPv4Address &addr, Report &report=(ts::CerrReport::Instance())) |
Set the outgoing local interface for multicast messages. | |
bool | setOutgoingMulticast (const UString &name, Report &report=(ts::CerrReport::Instance())) |
Set the outgoing local interface for multicast messages. | |
bool | setReceiveBufferSize (size_t size, Report &report=(ts::CerrReport::Instance())) |
Set the receive buffer size. | |
bool | setReceiveTimeout (cn::milliseconds timeout, Report &report=(ts::CerrReport::Instance())) |
Set the receive timeout. | |
bool | setReceiveTimestamps (bool on, Report &report=(ts::CerrReport::Instance())) |
Enable or disable the generation of receive timestamps. | |
bool | setSendBufferSize (size_t size, Report &report=(ts::CerrReport::Instance())) |
Set the send buffer size. | |
bool | setTOS (int tos, Report &report=(ts::CerrReport::Instance())) |
Set the Type Of Service (TOS) option. | |
bool | setTTL (int ttl, bool multicast, Report &report=(ts::CerrReport::Instance())) |
Set the Time To Live (TTL) option. | |
bool | setTTL (int ttl, Report &report=(ts::CerrReport::Instance())) |
Set the Time To Live (TTL) option. | |
Protected Member Functions | |
bool | createSocket (int domain, int type, int protocol, Report &report) |
Create the socket. | |
virtual void | declareOpened (SysSocketType sock, Report &report) |
Set an open socket descriptor from a subclass. | |
UDP Socket.
ts::UDPSocket::UDPSocket | ( | bool | auto_open = false , |
Report & | report = (ts::CerrReport::Instance()) |
||
) |
Constructor.
[in] | auto_open | If true, call open() immediately. |
[in,out] | report | Where to report error. |
bool ts::UDPSocket::bind | ( | const IPv4SocketAddress & | addr, |
Report & | report = (ts::CerrReport::Instance()) |
||
) |
Bind to a local address and port.
The IP address part of the socket address must one of:
Special note for receiving multicast on most Unix systems (at least Linux and macOS): The IP address shall be either AnyAddress or the multicast group address. Do not specify a local address to receive multicast on Unix.
The port number part of the socket address must be one of:
[in] | addr | Local socket address to bind to. |
[in,out] | report | Where to report error. |
bool ts::UDPSocket::setDefaultDestination | ( | const IPv4SocketAddress & | addr, |
Report & | report = (ts::CerrReport::Instance()) |
||
) |
Set a default destination address and port for outgoing messages.
There are two versions of the send() method. One of them explicitly specifies the destination of the packet to send. The second version does not specify a destination; the packet is sent to the default destination.
[in] | addr | Socket address of the destination. Both address and port are mandatory in the socket address, they cannot be set to IPv4Address::AnyAddress or IPv4SocketAddress::AnyPort. |
[in,out] | report | Where to report error. |
bool ts::UDPSocket::setDefaultDestination | ( | const UString & | name, |
Report & | report = (ts::CerrReport::Instance()) |
||
) |
Set a default destination address and port for outgoing messages.
There are two versions of the send() method. One of them explicitly specifies the destination of the packet to send. The second version does not specify a destination; the packet is sent to the default destination.
[in] | name | A string describing the socket address of the destination. See IPv4SocketAddress::resolve() for a description of the expected string format. |
[in,out] | report | Where to report error. |
|
inline |
Get the default destination address and port for outgoing messages.
bool ts::UDPSocket::setOutgoingMulticast | ( | const IPv4Address & | addr, |
Report & | report = (ts::CerrReport::Instance()) |
||
) |
Set the outgoing local interface for multicast messages.
[in] | addr | IP address of a local interface. |
[in,out] | report | Where to report error. |
bool ts::UDPSocket::setOutgoingMulticast | ( | const UString & | name, |
Report & | report = (ts::CerrReport::Instance()) |
||
) |
Set the outgoing local interface for multicast messages.
[in] | name | A string describing the IP address of a local interface. See IPv4Address::resolve() for a description of the expected string format. |
[in,out] | report | Where to report error. |
bool ts::UDPSocket::setTTL | ( | int | ttl, |
bool | multicast, | ||
Report & | report = (ts::CerrReport::Instance()) |
||
) |
Set the Time To Live (TTL) option.
[in] | ttl | The TTL value, ie. the maximum number of "hops" between routers before an IP packet is dropped. |
[in] | multicast | When true, set the multicast TTL option. When false, set the unicast TTL option. |
[in,out] | report | Where to report error. |
|
inline |
Set the Time To Live (TTL) option.
If the default destination is a multicast address, set the multicast TTL option. Otherwise, set the unicast TTL option.
[in] | ttl | The TTL value, ie. the maximum number of "hops" between routers before an IP packet is dropped. |
[in,out] | report | Where to report error. |
bool ts::UDPSocket::setTOS | ( | int | tos, |
Report & | report = (ts::CerrReport::Instance()) |
||
) |
Set the Type Of Service (TOS) option.
Note that correct support for this option depends on the operating system. Typically, it never worked correctly on Windows.
[in] | tos | The TOS value. |
[in,out] | report | Where to report error. |
bool ts::UDPSocket::setMulticastLoop | ( | bool | on, |
Report & | report = (ts::CerrReport::Instance()) |
||
) |
Set the multicast loop option.
By default, the multicast packets are looped back on local interfaces. Use this to disable multicast loopback.
[in] | on | It true, multicast loopback is on. When false, it is off. |
[in,out] | report | Where to report error. |
bool ts::UDPSocket::setReceiveTimestamps | ( | bool | on, |
Report & | report = (ts::CerrReport::Instance()) |
||
) |
Enable or disable the generation of receive timestamps.
When enabled, each received UDP packets comes with a time stamp (see receive()). When possible, a hardware timestamp from the NIC is received. Otherwise, a software timestamp is generated by the kernel.
When enabled, this option is a @æ request, not a requirement. Currently, this option is supported on Linux only. It is ignored on other systems.
[in] | on | If true, receive timestamps are activated on the socket. Otherwise, they are disabled. |
[in,out] | report | Where to report error. |
bool ts::UDPSocket::setBroadcast | ( | bool | on, |
Report & | report = (ts::CerrReport::Instance()) |
||
) |
Enable or disable the broadcast option.
[in] | on | If true, broadcast is activated on the socket. Otherwise, it is disabled. |
[in,out] | report | Where to report error. |
bool ts::UDPSocket::setBroadcastIfRequired | ( | const IPv4Address | destination, |
Report & | report = (ts::CerrReport::Instance()) |
||
) |
Enable or disable the broadcast option, based on an IP address.
[in] | destination | An hypothetical destination address. If this address is the broadcast address of a local interface, the broadcast option is set. Otherwise, the broadcast option is unchanged. |
[in,out] | report | Where to report error. |
bool ts::UDPSocket::addMembership | ( | const IPv4Address & | multicast, |
const IPv4Address & | local, | ||
const IPv4Address & | source = IPv4Address() , |
||
Report & | report = (ts::CerrReport::Instance()) |
||
) |
Join a multicast group.
This method indicates that the application wishes to receive multicast packets which are sent to a specific multicast address. Specifying a non-default source address, source-specific multicast (SSM) is used.
[in] | multicast | Multicast IP address to listen to. |
[in] | local | IP address of a local interface on which to listen. If set to IPv4Address::AnyAddress, the application lets the system selects the appropriate local interface. |
[in] | source | Source address for SSM. |
[in,out] | report | Where to report error. |
bool ts::UDPSocket::addMembershipAll | ( | const IPv4Address & | multicast, |
const IPv4Address & | source = IPv4Address() , |
||
Report & | report = (ts::CerrReport::Instance()) |
||
) |
Join a multicast group.
This method indicates that the application wishes to receive multicast packets which are sent to a specific multicast address. Specifying a non-default source address, source-specific multicast (SSM) is used.
Using this method, the application listens on all local interfaces.
[in] | multicast | Multicast IP address to listen to. |
[in] | source | Source address for SSM. |
[in,out] | report | Where to report error. |
bool ts::UDPSocket::addMembershipDefault | ( | const IPv4Address & | multicast, |
const IPv4Address & | source = IPv4Address() , |
||
Report & | report = (ts::CerrReport::Instance()) |
||
) |
Join a multicast group.
This method indicates that the application wishes to receive multicast packets which are sent to a specific multicast address. Specifying a non-default source address, source-specific multicast (SSM) is used.
Using this method, the application lets the system selects the appropriate local interface.
[in] | multicast | Multicast IP address to listen to. |
[in] | source | Source address for SSM. |
[in,out] | report | Where to report error. |
bool ts::UDPSocket::dropMembership | ( | Report & | report = (ts::CerrReport::Instance()) | ) |
Drop all multicast membership requests, including source-specific multicast.
[in,out] | report | Where to report error. |
|
virtual |
Send a message to a destination address and port.
[in] | data | Address of the message to send. |
[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 IPv4Address::AnyAddress or IPv4SocketAddress::AnyPort. |
[in,out] | report | Where to report error. |
|
virtual |
Send a message to the default destination address and port.
[in] | data | Address of the message to send. |
[in] | size | Size in bytes of the message to send. |
[in,out] | report | Where to report error. |
|
virtual |
Receive a message.
[out] | data | Address of the buffer for the received message. |
[in] | max_size | Size in bytes of the reception buffer. |
[out] | ret_size | Size in bytes of the received message. Will never be larger than max_size. |
[out] | sender | Socket address of the sender. |
[out] | destination | Socket address of the packet destination. Can be useful to check in multicast packets. |
[in] | abort | If non-zero, invoked when I/O is interrupted (in case of user-interrupt, return, otherwise retry). |
[in,out] | report | Where to report error. |
[out] | timestamp | When not null, return the receive timestamp in micro-seconds. Use setReceiveTimestamps() to enable the generation of receive timestamps. If the returned value is negative, no timestamp is available. |
Reimplemented in ts::UDPReceiver.
|
overridevirtual |
Open the socket.
[in,out] | report | Where to report error. |
Implements ts::Socket.
Reimplemented in ts::UDPReceiver.
|
overridevirtual |
Close the socket.
[in,out] | report | Where to report error. |
Reimplemented from ts::Socket.
|
inlineinherited |
Check if socket is open.
|
inherited |
Set the send buffer size.
[in] | size | Send buffer size in bytes. |
[in,out] | report | Where to report error. |
|
inherited |
Set the receive buffer size.
[in] | size | Receive buffer size in bytes. |
[in,out] | report | Where to report error. |
|
inherited |
Set the receive timeout.
[in] | timeout | Receive timeout in milliseconds. If negative, receive timeout is not used. |
[in,out] | report | Where to report error. |
|
inherited |
Set the "reuse port" option.
[in] | reuse_port | If true, the socket is allowed to reuse a local UDP port which is already bound. |
[in,out] | report | Where to report error. |
|
inherited |
Get local socket address.
[out] | addr | Local socket address of the connection. |
[in,out] | report | Where to report error. |
|
inlineinherited |
Get the underlying socket device handle (use with care).
This method is reserved for low-level operations and should not be used by normal applications.
|
protectedinherited |
|
protectedvirtualinherited |
Set an open socket descriptor from a subclass.
This method is used by a server to declare that a client socket has just become opened.
[in] | sock | New socket descriptor. |
[in,out] | report | Where to report error. |
Reimplemented in ts::TCPSocket.