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

UDP Socket. More...

#include <tsUDPSocket.h>

Inheritance diagram for ts::UDPSocket:
Collaboration diagram for ts::UDPSocket:

Public Types

using SuperClass = Socket
 Reference to the superclass.
 
enum class  TimeStampType {
  NONE ,
  SOFTWARE ,
  HARDWARE
}
 Type of timestamp which is returned by receive(). More...
 

Public Member Functions

 UDPSocket (Report *report=nullptr, bool auto_open=false, IP gen=IP::Any, bool non_blocking=false)
 Constructor.
 
 UDPSocket (ReporterBase *delegate, bool auto_open=false, IP gen=IP::Any, bool non_blocking=false)
 Constructor.
 
virtual ~UDPSocket () override
 Destructor.
 
bool addMembership (const IPAddress &multicast, const IPAddress &local, const IPAddress &source=IPAddress())
 Join a multicast group.
 
bool addMembership (const IPAddress &multicast, int interface_index, const IPAddress &source=IPAddress())
 Join a multicast group.
 
bool addMembershipAll (const IPAddress &multicast, const IPAddress &source=IPAddress(), bool link_local=true)
 Join a multicast group.
 
bool addMembershipDefault (const IPAddress &multicast, const IPAddress &source=IPAddress())
 Join a multicast group.
 
void addSubscription (SocketHandlerInterface *handler)
 Add a subscriber to open/close events.
 
bool bind (const IPSocketAddress &addr)
 Bind to a local address and port.
 
void cancelSubscription (SocketHandlerInterface *handler)
 Remove a subscriber to open/close events.
 
virtual bool close (bool silent=false) override
 Close the socket.
 
bool dropMembership ()
 Drop all multicast membership requests, including source-specific multicast.
 
IP generation () const
 Get the IP generation with which the socket was open.
 
IPSocketAddress getDefaultDestination () const
 Get the default destination address and port for outgoing messages.
 
bool getLocalAddress (IPSocketAddress &addr) const
 Get local socket address.
 
bool getReceiveStatus (IOSB *iosb, IPSocketAddress &sender, IPSocketAddress &destination, cn::microseconds *timestamp=nullptr, TimeStampType *timestamp_type=nullptr) const
 Get the result of an asynchronous receive().
 
SysSocketType getSocket () const
 Get the underlying socket device handle (use with care).
 
bool isNonBlocking () const
 Check if the device is in non-blocking mode.
 
bool isOpen () const
 Check if socket is open.
 
bool muteReport (bool mute)
 Temporarily mute the associated report.
 
virtual bool open (IP gen) override
 Open the socket.
 
virtual bool receive (void *data, size_t max_size, size_t &ret_size, IPSocketAddress &sender, IPSocketAddress &destination, const AbortInterface *abort=nullptr, cn::microseconds *timestamp=nullptr, TimeStampType *timestamp_type=nullptr, IOSB *iosb=nullptr)
 Receive a message.
 
Reportreport () const
 Access the Report which is associated with this object.
 
bool reusePort (bool reuse_port)
 Set the "reuse port" option.
 
virtual bool send (const void *data, size_t size, const IPSocketAddress &destination, IOSB *iosb=nullptr)
 Send a message to a destination address and port.
 
virtual bool send (const void *data, size_t size, IOSB *iosb=nullptr)
 Send a message to the default destination address and port.
 
bool setBroadcast (bool on)
 Enable or disable the broadcast option.
 
bool setBroadcastIfRequired (const IPAddress destination)
 Enable or disable the broadcast option, based on an IP address.
 
bool setDefaultDestination (const IPSocketAddress &addr)
 Set a default destination address and port for outgoing messages.
 
bool setDefaultDestination (const UString &name)
 Set a default destination address and port for outgoing messages.
 
bool setMulticastLoop (bool on)
 Set the multicast loop option.
 
bool setNonBlocking (bool non_blocking)
 Set the device in non-blocking mode.
 
bool setOutgoingMulticast (const IPAddress &addr)
 Set the outgoing local interface for multicast messages.
 
bool setOutgoingMulticast (const UString &name)
 Set the outgoing local interface for multicast messages.
 
bool setReceiveBufferSize (size_t size)
 Set the receive buffer size.
 
bool setReceiveTimeout (cn::milliseconds timeout)
 Set the receive timeout.
 
bool setReceiveTimestamps (bool on)
 Enable or disable the generation of receive timestamps.
 
ReportsetReport (Report *report)
 Associate this object with another Report to log errors.
 
ReporterBasesetReport (ReporterBase *delegate)
 Associate this object with another ReporterBase to log errors.
 
bool setSendBufferSize (size_t size)
 Set the send buffer size.
 
bool setTOS (int tos)
 Set the Type Of Service (TOS) or Traffic Class (IPv6) option.
 
bool setTTL (int ttl)
 Set the Time To Live (TTL) option.
 
bool setTTL (int ttl, bool multicast)
 Set the Time To Live (TTL) option.
 

Static Public Member Functions

static int SilentLevel (bool silent)
 Compute a log severity level from a "silent" parameter.
 

Protected Member Functions

virtual bool allowSetNonBlocking () const override
 Check that the non-blocking mode can be set.
 
bool checkNonBlocking (bool non_blocking, const UChar *opname)
 Check the blocking mode of a device.
 
bool checkNonBlocking (IOSB *iosb, const UChar *opname)
 Check the blocking mode of a device.
 
bool convert (IPAddress &addr) const
 Convert an IP address to make it compatible with the socket IP generation.
 
bool createSocket (IP gen, int type, int protocol)
 Create the socket.
 
virtual void declareOpened (SysSocketType sock)
 Set an open socket descriptor from a subclass.
 
bool setSystemNonBlocking (SysSocketType fd, bool non_blocking)
 Convenience method to set a system file descriptor or socket handle in non-blocking mode.
 

Detailed Description

UDP Socket.

Member Enumeration Documentation

◆ TimeStampType

enum class ts::UDPSocket::TimeStampType
strong

Type of timestamp which is returned by receive().

Enumerator
NONE 

No timestamp.

SOFTWARE 

Software time stamp, generated by the kernel.

HARDWARE 

Hardware time stamp, generated by the NIC, when supported.

Constructor & Destructor Documentation

◆ UDPSocket() [1/2]

ts::UDPSocket::UDPSocket ( Report report = nullptr,
bool  auto_open = false,
IP  gen = IP::Any,
bool  non_blocking = false 
)
explicit

Constructor.

Parameters
[in]reportWhere to report errors. The report object must remain valid as long as this object exists or setReport() is used with another Report object. If report is null, log messages are discarded.
[in]auto_openIf true, call open() immediately.
[in]genIP generation, IPv4 or IPv6. If set to IP::Any, this socket can receive IPv4 and IPv6 datagrams. If gen is IP::v6, the socket is created with option IPV6_V6ONLY set.
[in]non_blockingIt true, the device is initially set in non-blocking mode.

◆ UDPSocket() [2/2]

ts::UDPSocket::UDPSocket ( ReporterBase delegate,
bool  auto_open = false,
IP  gen = IP::Any,
bool  non_blocking = false 
)
explicit

Constructor.

Parameters
[in]delegateUse the report of another ReporterBase. If delegate is null, log messages are discarded.
[in]auto_openIf true, call open() immediately.
[in]genIP generation, IPv4 or IPv6. If set to IP::Any, this socket can receive IPv4 and IPv6 datagrams. If gen is IP::v6, the socket is created with option IPV6_V6ONLY set.
[in]non_blockingIt true, the device is initially set in non-blocking mode.

Member Function Documentation

◆ setDefaultDestination() [1/2]

bool ts::UDPSocket::setDefaultDestination ( const IPSocketAddress addr)

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.

Parameters
[in]addrSocket address of the destination. Both address and port are mandatory in the socket address, they cannot be set to IPAddress::AnyAddress4 or IPSocketAddress::AnyPort.
Returns
True on success, false on error.

◆ setDefaultDestination() [2/2]

bool ts::UDPSocket::setDefaultDestination ( const UString name)

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.

Parameters
[in]nameA string describing the socket address of the destination. See IPSocketAddress::resolve() for a description of the expected string format.
Returns
True on success, false on error.

◆ getDefaultDestination()

IPSocketAddress ts::UDPSocket::getDefaultDestination ( ) const
inline

Get the default destination address and port for outgoing messages.

Returns
The default destination address and port for outgoing messages.

◆ setOutgoingMulticast() [1/2]

bool ts::UDPSocket::setOutgoingMulticast ( const IPAddress addr)

Set the outgoing local interface for multicast messages.

Parameters
[in]addrIP address of a local interface.
Returns
True on success, false on error.

◆ setOutgoingMulticast() [2/2]

bool ts::UDPSocket::setOutgoingMulticast ( const UString name)

Set the outgoing local interface for multicast messages.

Parameters
[in]nameA string describing the IP address of a local interface. See IPAddress::resolve() for a description of the expected string format.
Returns
True on success, false on error.

◆ setTTL() [1/2]

bool ts::UDPSocket::setTTL ( int  ttl,
bool  multicast 
)

Set the Time To Live (TTL) option.

Parameters
[in]ttlThe TTL value, ie. the maximum number of "hops" between routers before an IP packet is dropped.
[in]multicastWhen true, set the multicast TTL option. When false, set the unicast TTL option.
Returns
True on success, false on error.

◆ setTTL() [2/2]

bool ts::UDPSocket::setTTL ( int  ttl)
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.

Parameters
[in]ttlThe TTL value, ie. the maximum number of "hops" between routers before an IP packet is dropped.
Returns
True on success, false on error.

◆ setTOS()

bool ts::UDPSocket::setTOS ( int  tos)

Set the Type Of Service (TOS) or Traffic Class (IPv6) option.

The interpretation of the tos parameter depends in the IP generation. With IPv4, this is a "type of service" value. With IPv6, this is a "traffic class" value.

Note that correct support for this option depends on the operating system. Typically, it never worked correctly on Windows.

Parameters
[in]tosThe type of service (IPv4) or traffic class (IPv6) value.
Returns
True on success, false on error.

◆ setMulticastLoop()

bool ts::UDPSocket::setMulticastLoop ( bool  on)

Set the multicast loop option.

By default, the multicast packets are looped back on local interfaces. Use this to disable multicast loopback.

Parameters
[in]onIt true, multicast loopback is on. When false, it is off.
Returns
True on success, false on error.

◆ setReceiveTimestamps()

bool ts::UDPSocket::setReceiveTimestamps ( bool  on)

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. This option is supported on Linux and macOS only. It is ignored on other systems.

Parameters
[in]onIf true, receive timestamps are activated on the socket. Otherwise, they are disabled.
Returns
True on success, false on error.

◆ setBroadcast()

bool ts::UDPSocket::setBroadcast ( bool  on)

Enable or disable the broadcast option.

Parameters
[in]onIf true, broadcast is activated on the socket. Otherwise, it is disabled.
Returns
True on success, false on error.

◆ setBroadcastIfRequired()

bool ts::UDPSocket::setBroadcastIfRequired ( const IPAddress  destination)

Enable or disable the broadcast option, based on an IP address.

Parameters
[in]destinationAn 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.
Returns
True on success, false on error.

◆ addMembership() [1/2]

bool ts::UDPSocket::addMembership ( const IPAddress multicast,
const IPAddress local,
const IPAddress source = IPAddress() 
)
inline

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. Note that source-specific multicast exists on IPv4 only.

Parameters
[in]multicastMulticast IP address to listen to.
[in]localIP address of a local interface on which to listen. If set to IPAddress::AnyAddress4, the application lets the system selects the appropriate local interface.
[in]sourceSource address for SSM. Ignored on IPv6 socket.
Returns
True on success, false on error.

◆ addMembership() [2/2]

bool ts::UDPSocket::addMembership ( const IPAddress multicast,
int  interface_index,
const IPAddress source = IPAddress() 
)
inline

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. Note that source-specific multicast exists on IPv4 only.

Parameters
[in]multicastMulticast IP address to listen to.
[in]interface_indexIndex of a local interface on which to listen. If set to zero, the application lets the system selects the appropriate local interface.
[in]sourceSource address for SSM. Ignored on IPv6 socket.
Returns
True on success, false on error.

◆ addMembershipAll()

bool ts::UDPSocket::addMembershipAll ( const IPAddress multicast,
const IPAddress source = IPAddress(),
bool  link_local = true 
)

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.

Parameters
[in]multicastMulticast IP address to listen to.
[in]sourceSource address for SSM.
[in]link_localIf true, also add membership on link-local addresses, otherwise ignore them.
Returns
True on success, false on error.

◆ addMembershipDefault()

bool ts::UDPSocket::addMembershipDefault ( const IPAddress multicast,
const IPAddress source = IPAddress() 
)
inline

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.

Parameters
[in]multicastMulticast IP address to listen to.
[in]sourceSource address for SSM.
Returns
True on success, false on error.

◆ dropMembership()

bool ts::UDPSocket::dropMembership ( )

Drop all multicast membership requests, including source-specific multicast.

Returns
True on success, false on error.

◆ send() [1/2]

virtual bool ts::UDPSocket::send ( const void *  data,
size_t  size,
const IPSocketAddress destination,
IOSB iosb = nullptr 
)
virtual

Send a message to a destination address and port.

Parameters
[in]dataAddress of the message to send.
[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,out]iosbAddress of an IOSB structure. If non-null, the socket must be in non-blocking mode. When null, the socket must be in blocking mode (the default). See the description of IOSB. Important: The parameter iosb should not be used by applications. It should be used only by "reactive classes", which work in combination with a Reactor.
Returns
True on success, false on error.

◆ send() [2/2]

virtual bool ts::UDPSocket::send ( const void *  data,
size_t  size,
IOSB iosb = nullptr 
)
virtual

Send a message to the default destination address and port.

Parameters
[in]dataAddress of the message to send.
[in]sizeSize in bytes of the message to send.
[in,out]iosbAddress of an IOSB structure. If non-null, the socket must be in non-blocking mode. When null, the socket must be in blocking mode (the default). See the description of IOSB. Important: The parameter iosb should not be used by applications. It should be used only by "reactive classes", which work in combination with a Reactor.
Returns
True on success, false on error.

◆ receive()

virtual bool ts::UDPSocket::receive ( void *  data,
size_t  max_size,
size_t &  ret_size,
IPSocketAddress sender,
IPSocketAddress destination,
const AbortInterface abort = nullptr,
cn::microseconds *  timestamp = nullptr,
TimeStampType timestamp_type = nullptr,
IOSB iosb = nullptr 
)
virtual

Receive a message.

Parameters
[out]dataAddress of the buffer for the received message.
[in]max_sizeSize in bytes of the reception buffer.
[out]ret_sizeSize in bytes of the received message. Will never be larger than max_size.
[out]senderSocket address of the sender.
[out]destinationSocket address of the packet destination. Can be useful to check in multicast packets.
[in]abortIf non-zero, invoked when I/O is interrupted (in case of user-interrupt, return, otherwise retry).
[out]timestampWhen 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.
[out]timestamp_typeWhen not null, return the type of receive timestamp.
[in,out]iosbAddress of an IOSB structure. If non-null, the socket must be in non-blocking mode. When null, the socket must be in blocking mode (the default). See the description of IOSB. Important: The parameter iosb should not be used by applications. It should be used only by "reactive classes", which work in combination with a Reactor.
Returns
True on success, false on error.

Reimplemented in ts::UDPReceiver.

◆ getReceiveStatus()

bool ts::UDPSocket::getReceiveStatus ( IOSB iosb,
IPSocketAddress sender,
IPSocketAddress destination,
cn::microseconds *  timestamp = nullptr,
TimeStampType timestamp_type = nullptr 
) const

Get the result of an asynchronous receive().

This method shall be used with asynchronous I/O only. It returns an error when the system uses non-blocking I/O instead of asynchronous I/O.

Parameters
[in,out]iosbAddress of the IOSB structure which was used when receive() was called.
[out]senderSocket address of the sender.
[out]destinationSocket address of the packet destination. Can be useful to check in multicast packets.
[out]timestampWhen 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.
[out]timestamp_typeWhen not null, return the type of receive timestamp.
Returns
True on success, false on error.

◆ open()

virtual bool ts::UDPSocket::open ( IP  gen)
overridevirtual

Open the socket.

Parameters
[in]genIP generation, IPv4 or IPv6. If set to IP::Any, open an IPv6 socket (IPv4 connections allowed).
Returns
True on success, false on error.

Implements ts::Socket.

Reimplemented in ts::UDPReceiver.

◆ close()

virtual bool ts::UDPSocket::close ( bool  silent = false)
overridevirtual

Close the socket.

If overridden by a subclass, the superclass must be called at the end of the overridden close().

Parameters
[in]silentIf true, do not report errors through the logger. This is typically useful when the socket is in some error condition and closing it is necessary although it may generate additional meaningless errors.
Returns
True on success, false on error.

Reimplemented from ts::Socket.

◆ isOpen()

bool ts::Socket::isOpen ( ) const
inlineinherited

Check if socket is open.

Returns
True if socket is open.

◆ generation()

IP ts::Socket::generation ( ) const
inlineinherited

Get the IP generation with which the socket was open.

Returns
The IP generation used to open the socket. Never IP::Any.

◆ setSendBufferSize()

bool ts::Socket::setSendBufferSize ( size_t  size)
inherited

Set the send buffer size.

Parameters
[in]sizeSend buffer size in bytes.
Returns
True on success, false on error.

◆ setReceiveBufferSize()

bool ts::Socket::setReceiveBufferSize ( size_t  size)
inherited

Set the receive buffer size.

Parameters
[in]sizeReceive buffer size in bytes.
Returns
True on success, false on error.

◆ setReceiveTimeout()

bool ts::Socket::setReceiveTimeout ( cn::milliseconds  timeout)
inherited

Set the receive timeout.

Parameters
[in]timeoutReceive timeout in milliseconds. If negative or zero, receive timeout is not used, reception waits forever.
Returns
True on success, false on error.

◆ reusePort()

bool ts::Socket::reusePort ( bool  reuse_port)
inherited

Set the "reuse port" option.

Parameters
[in]reuse_portIf true, the socket is allowed to reuse a local UDP port which is already bound.
Returns
True on success, false on error.

◆ bind()

bool ts::Socket::bind ( const IPSocketAddress addr)
inherited

Bind to a local address and port.

The IP address part of the socket address must one of:

  • IPAddress::AnyAddress4.
    • UDP: Any local interface may be used to send or receive UDP datagrams. For each outgoing packet, the actual interface is selected by the kernel based on the routing rules. Incoming UDP packets for the selected port will be accepted from any local interface.
    • TCP client: Any local interface may be used to connect to a server.
    • TCP server: Any local interface may be used to receive incoming client connections.
  • The IP address of an interface of the local system.
    • UDP: Outgoing packets will be unconditionally sent through this interface. Incoming UDP packets for the selected port will be accepted only when they arrive through the selected interface.
    • TCP client: Outgoing connections will be only allowed through this interface.
    • TCP server: Incoming client connections will be accepted only when they arrive through the selected interface.

Special note for receiving multicast on most Unix systems (at least Linux and macOS): The IP address shall be either AnyAddress4 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:

  • IPSocketAddress::AnyPort. The socket is bound to an arbitrary unused local UDP or TCP port. This is the usual configuration for a TCP client.
  • A specific port number. If this UDP or TCP port is already bound by another local socket of the same type, the bind operation fails, unless the "reuse port" option has already been set.
Parameters
[in]addrLocal socket address to bind to.
Returns
True on success, false on error.

◆ getLocalAddress()

bool ts::Socket::getLocalAddress ( IPSocketAddress addr) const
inherited

Get local socket address.

Parameters
[out]addrLocal socket address of the connection.
Returns
True on success, false on error.

◆ getSocket()

SysSocketType ts::Socket::getSocket ( ) const
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.

Returns
The underlying socket system device handle or file descriptor. Return SYS_SOCKET_INVALID if the socket is not open.

◆ addSubscription()

void ts::Socket::addSubscription ( SocketHandlerInterface handler)
inherited

Add a subscriber to open/close events.

Parameters
[in]handlerThe object to call on open() and close().

◆ cancelSubscription()

void ts::Socket::cancelSubscription ( SocketHandlerInterface handler)
inherited

Remove a subscriber to open/close events.

Parameters
[in]handlerThe object to no longer call on open() and close().

◆ createSocket()

bool ts::Socket::createSocket ( IP  gen,
int  type,
int  protocol 
)
protectedinherited

Create the socket.

Parameters
[in]genIP generation.
[in]typeSocket type: SOCK_STREAM, SOCK_DGRAM
[in]protocolSocket protocol: IPPROTO_TCP, IPPROTO_UDP
Returns
True on success, false on error.
See also
open(ge, Report&)

◆ declareOpened()

virtual void ts::Socket::declareOpened ( SysSocketType  sock)
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.

Parameters
[in]sockNew socket descriptor.

Reimplemented in ts::TCPSocket.

◆ convert()

bool ts::Socket::convert ( IPAddress addr) const
protectedinherited

Convert an IP address to make it compatible with the socket IP generation.

Parameters
addr[in,out] The address to convert.
Returns
True on success, false on error.

◆ allowSetNonBlocking()

virtual bool ts::Socket::allowSetNonBlocking ( ) const
overrideprotectedvirtualinherited

Check that the non-blocking mode can be set.

Must be implemented by subclasses which do not support setting the non-blocking in certain states, such as after being opened. The default implementation always allows setting the non-blocking mode.

Returns
True if setting the non-blocking mode is allowed, false otherwise.

Reimplemented from ts::NonBlockingDevice.

◆ setNonBlocking()

bool ts::NonBlockingDevice::setNonBlocking ( bool  non_blocking)
inherited

Set the device in non-blocking mode.

Important: Usually, this method must be called before opening the device, whatever it means. Otherwise it is ignored and the device blocking mode is unchanged.

Parameters
[in]non_blockingIt true, the device is set in non-blocking mode.
Returns
True on success, false if the device is already open and the non-blocking mode is unchanged.

◆ isNonBlocking()

bool ts::NonBlockingDevice::isNonBlocking ( ) const
inlineinherited

Check if the device is in non-blocking mode.

Returns
True if the device is in non-blocking mode, false otherwise.
See also
setNonBlocking()

◆ checkNonBlocking() [1/2]

bool ts::NonBlockingDevice::checkNonBlocking ( bool  non_blocking,
const UChar opname 
)
protectedinherited

Check the blocking mode of a device.

Called by subclass methods which are explicitly called in blocking or non-blocking mode.

Parameters
[in]non_blockingThe required non-blocking mode.
[in]opnameName of the operation, for the error message.
Returns
True on success, false on error.

◆ checkNonBlocking() [2/2]

bool ts::NonBlockingDevice::checkNonBlocking ( IOSB iosb,
const UChar opname 
)
protectedinherited

Check the blocking mode of a device.

Called by subclass methods which are explicitly called in blocking or non-blocking mode.

Parameters
[in,out]iosbAddress of an IOSB structure. If non-null, we are in non-blocking mode. When null, we are in blocking mode. When non-null, pending is reset to false and overlap is zeroed.
[in]opnameName of the operation, for the error message.
Returns
True on success, false on error.

◆ setSystemNonBlocking()

bool ts::NonBlockingDevice::setSystemNonBlocking ( SysSocketType  fd,
bool  non_blocking 
)
protectedinherited

Convenience method to set a system file descriptor or socket handle in non-blocking mode.

Parameters
[in]fdSystem file descriptor (UNIX) or socket handle (Windows). On Windows, non-socket devices shall be opened with flag FILE_FLAG_OVERLAPPED instead of using this method.
[in]non_blockingIt true, the device is set in non-blocking mode.
Returns
True on success, false on error.

◆ report()

Report & ts::ReporterBase::report ( ) const
inherited

Access the Report which is associated with this object.

Can be called from another thread only if the Report object is thread-safe.

Returns
A reference to the associated report.

◆ setReport() [1/2]

Report * ts::ReporterBase::setReport ( Report report)
inherited

Associate this object with another Report to log errors.

Parameters
[in]reportWhere to report errors. The report object must remain valid as long as this object exists or setReport() is used with another Report object. If report is null, log messages are discarded.
Returns
The address of the previous Report object or a null pointer if there was none.

◆ setReport() [2/2]

ReporterBase * ts::ReporterBase::setReport ( ReporterBase delegate)
inherited

Associate this object with another ReporterBase to log errors.

Parameters
[in]delegateUse the report of another ReporterBase. If delegate is null, the previous explicit Report is used..
Returns
The address of the previous ReporterBase object or a null pointer if there was none.

◆ muteReport()

bool ts::ReporterBase::muteReport ( bool  mute)
inherited

Temporarily mute the associated report.

Parameters
[in]muteIt true, report() will return a null report (log messages are discarded), until muteReport() is invoked again with mute set to false.
Returns
Previous state of the mute field.

◆ SilentLevel()

static int ts::ReporterBase::SilentLevel ( bool  silent)
inlinestaticinherited

Compute a log severity level from a "silent" parameter.

Some subclass methods have a "silent" parameter to avoid reporting errors which may be insignificant, typically when closing a device after an error, in which case the close operation may produce other errors if the previous error left the device in an inconsistent state. While those errors should not be displayed as errors, we still display them at debug level.

Parameters
[in]silentIf true, do not report errors, report debug messages instead.
Returns
Error when silent is false, Debug otherwise.

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