![]() |
TSDuck v3.45-4766
MPEG Transport Stream Toolkit
|
#include <tsUDPSocket.h>


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, 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 (SubscriptionHandlerInterface *handler) |
| Add a subscriber to open/close events. | |
| bool | bind (const IPSocketAddress &addr) |
| Bind to a local address and port. | |
| void | cancelSubscription (SubscriptionHandlerInterface *handler) |
| Remove a subscriber to open/close events. | |
| virtual bool | close (bool silent=false) final |
| 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. | |
| SysHandleType | getHandle () const |
| Get the underlying file descriptor or device handle. | |
| bool | getLocalAddress (IPSocketAddress &addr) const |
| Get local socket address. | |
| virtual SysHandleType | getReadHandle () const override |
| Get the underlying file descriptor or device handle for read operations. | |
| SysSocketType | getReadSocket () const |
| Get the underlying file descriptor or device handle as a system socket handle for read operations. | |
| 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 file descriptor or device handle as a system socket handle. | |
| virtual SysHandleType | getWriteHandle () const override |
| Get the underlying file descriptor or device handle for write operations. | |
| SysSocketType | getWriteSocket () const |
| Get the underlying file descriptor or device handle as a system socket handle for write operations. | |
| bool | isNonBlocking () const |
| Check if the device is in non-blocking mode. | |
| bool | isOpen () const |
| Check if socket is open. | |
| bool | isSupportedByReactor (bool recheck=false) |
| Check if the device is supported by a reactor for non-blocking or asynchronous I/O. | |
| UString | localName () |
| Get the local address as a string. | |
| bool | muteReport (bool mute) |
| Temporarily mute the associated report. | |
| virtual bool | open (IP gen=IP::Any) final |
| 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. | |
| virtual Report & | report () const override |
| 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. | |
| Report * | setReport (Report *report) |
| Associate this object with another Report to log errors. | |
| ReporterBase * | setReport (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 bool | IsPendingStatus (int error_code) |
| This static method checks if a system error code means "I/O in progress" (asynchronous I/O) or "I/O would block" (non-blocking I/O). | |
| static int | SilentLevel (bool silent, int default_severity=Severity::Error) |
| 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. | |
| template<typename HANDLER , typename F > requires std::derived_from<HANDLER, SubscriptionHandlerInterface> | |
| void | callSubscribers (F &&func) |
| Call a handler on all subscribers, using a lambda expression. | |
| 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. | |
| virtual bool | closeImplementation (bool silent) override |
| Close the socket, actual implementation which may be overriden by subclasses. | |
| 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. | |
| int | genericSystemRead (void *addr, size_t max_size, size_t &ret_size, const AbortInterface *abort, NonBlockingDevice::IOSB *iosb, uint64_t position) |
| Generic system read operation. | |
| int | genericSystemWrite (const void *addr, size_t size, size_t &written_size, NonBlockingDevice::IOSB *iosb, uint64_t position) |
| Generic system write operation. | |
| virtual bool | openImplementation (IP gen) override |
| Open the socket, actual implementation which must be overriden by subclasses. | |
| bool | setSystemNonBlocking (bool non_blocking) |
| Low-level method to set the system file or socket descriptor in non-blocking mode. | |
UDP Socket.
|
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. |
|
explicit |
Constructor.
| [in] | report | Where 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_open | If true, call open() immediately. |
| [in] | gen | IP 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_blocking | It true, the device is initially set in non-blocking mode. |
|
explicit |
Constructor.
| [in] | delegate | Use the report of another ReporterBase. If delegate is null, log messages are discarded. |
| [in] | auto_open | If true, call open() immediately. |
| [in] | gen | IP 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_blocking | It true, the device is initially set in non-blocking mode. |
| 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.
| [in] | addr | 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. |
| 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.
| [in] | name | A string describing the socket address of the destination. See IPSocketAddress::resolve() for a description of the expected string format. |
|
inline |
Get the default destination address and port for outgoing messages.
| bool ts::UDPSocket::setOutgoingMulticast | ( | const IPAddress & | addr | ) |
Set the outgoing local interface for multicast messages.
| [in] | addr | IP address of a local interface. |
| bool ts::UDPSocket::setOutgoingMulticast | ( | const UString & | name | ) |
Set the outgoing local interface for multicast messages.
| [in] | name | A string describing the IP address of a local interface. See IPAddress::resolve() for a description of the expected string format. |
| bool ts::UDPSocket::setTTL | ( | int | ttl, |
| bool | multicast | ||
| ) |
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. |
|
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. |
| 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.
| [in] | tos | The type of service (IPv4) or traffic class (IPv6) value. |
| 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.
| [in] | on | It true, multicast loopback is on. When false, it is off. |
| 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.
| [in] | on | If true, receive timestamps are activated on the socket. Otherwise, they are disabled. |
| bool ts::UDPSocket::setBroadcast | ( | bool | on | ) |
Enable or disable the broadcast option.
| [in] | on | If true, broadcast is activated on the socket. Otherwise, it is disabled. |
| bool ts::UDPSocket::setBroadcastIfRequired | ( | const IPAddress | destination | ) |
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. |
|
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.
| [in] | multicast | Multicast IP address to listen to. |
| [in] | local | IP 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] | source | Source address for SSM. Ignored on IPv6 socket. |
|
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.
| [in] | multicast | Multicast IP address to listen to. |
| [in] | interface_index | Index of a local interface on which to listen. If set to zero, the application lets the system selects the appropriate local interface. |
| [in] | source | Source address for SSM. Ignored on IPv6 socket. |
| 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.
| [in] | multicast | Multicast IP address to listen to. |
| [in] | source | Source address for SSM. |
| [in] | link_local | If true, also add membership on link-local addresses, otherwise ignore them. |
|
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.
| [in] | multicast | Multicast IP address to listen to. |
| [in] | source | Source address for SSM. |
| bool ts::UDPSocket::dropMembership | ( | ) |
Drop all multicast membership requests, including source-specific multicast.
|
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 IPAddress::AnyAddress4 or IPSocketAddress::AnyPort. |
| [in,out] | iosb | Address 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. |
|
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] | iosb | Address 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. |
|
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). |
| [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. |
| [out] | timestamp_type | When not null, return the type of receive timestamp. |
| [in,out] | iosb | Address 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. |
Reimplemented in ts::UDPReceiver.
| 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.
| [in,out] | iosb | Address of the IOSB structure which was used when receive() was called. |
| [out] | sender | Socket address of the sender. |
| [out] | destination | Socket address of the packet destination. Can be useful to check in multicast packets. |
| [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. |
| [out] | timestamp_type | When not null, return the type of receive timestamp. |
|
overrideprotectedvirtual |
Open the socket, actual implementation which must be overriden by subclasses.
Never called when the application tries to open a socket which is already open.
| [in] | gen | IP generation, IPv4 or IPv6. If set to IP::Any, open an IPv6 socket (IPv4 connections allowed). |
Implements ts::Socket.
Reimplemented in ts::UDPReceiver.
|
overrideprotectedvirtual |
Close the socket, actual implementation which may be overriden by subclasses.
Never called when the application tries to close a socket which is not open. If overridden by a subclass, the superclass must be called at the end of the overridden close().
| [in] | silent | If 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. |
Reimplemented from ts::Socket.
Open the socket.
Subclasses are not permitted to override this one, they should implement openImplementation().
| [in] | gen | IP generation, IPv4 or IPv6. If set to IP::Any, open an IPv6 socket (IPv4 connections allowed). |
|
finalvirtualinherited |
Close the socket.
Subclasses are not permitted to override this one, they should implement closeImplementation().
| [in] | silent | If 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. |
|
inlineinherited |
Check if socket is open.
|
inlineinherited |
Get the IP generation with which the socket was open.
|
inherited |
Set the send buffer size.
| [in] | size | Send buffer size in bytes. |
|
inherited |
Set the receive buffer size.
| [in] | size | Receive buffer size in bytes. |
|
inherited |
Set the receive timeout.
| [in] | timeout | Receive timeout in milliseconds. If negative or zero, receive timeout is not used, reception waits forever. |
|
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. |
|
inherited |
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 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:
| [in] | addr | Local socket address to bind to. |
|
inherited |
Get local socket address.
| [out] | addr | Local socket address of the connection. |
|
inherited |
Get the local address as a string.
|
overridevirtualinherited |
Get the underlying file descriptor or device handle for read operations.
Subclasses should override this method.
Reimplemented from ts::NonBlockingDevice.
|
overridevirtualinherited |
Get the underlying file descriptor or device handle for write operations.
Subclasses should override this method.
Reimplemented from ts::NonBlockingDevice.
|
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. |
Reimplemented in ts::TCPSocket.
|
protectedinherited |
Convert an IP address to make it compatible with the socket IP generation.
| addr | [in,out] The address to convert. |
|
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.
Reimplemented from ts::NonBlockingDevice.
|
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.
| [in] | non_blocking | It true, the device is set in non-blocking mode. |
|
inlineinherited |
Check if the device is in non-blocking mode.
|
inherited |
Check if the device is supported by a reactor for non-blocking or asynchronous I/O.
| [in] | recheck | If true, force a recheck. If false and the device was previously checked, return the previous cached value. |
|
inlinestaticinherited |
This static method checks if a system error code means "I/O in progress" (asynchronous I/O) or "I/O would block" (non-blocking I/O).
| [in] | error_code | System error code. |
|
inherited |
Get the underlying file descriptor or device handle.
This method is reserved for low-level operations and should not be used by normal applications.
On UNIX systems, sockets are standard file descriptors. On Windows systems, sockets and devices handles are two distinct types (SOCKET, an integer type, and HANDLE, a pointer type). However, SOCKET and HANDLE have the same size and can be converted between each other. In practice, all Windows device handles are pointers. When Microsoft decided to implement the BSD socket API, they needed to represent sockets as integers. The integer is simply a cast of the HANDLE pointer.
In practice, the methods getHandle() and getSocket() return the same value, represented as two different portable types, SysHandleType and SysSocketType. Note that this types are defined as their real representation. On UNIX systems, both are defined as int and are compatible. However, on Windows systems, they are defined as HANDLE and SOCKET and are not compatible. So, accidentally mixing the two compiles on UNIX but not on Windows. Be careful to use the right type for the right usage.
There is one important difference between getHandle() and getSocket(): the error values, SYS_HANDLE_INVALID and SYS_SOCKET_INVALID. Be careful, these constants have distinct binary values on Windows. This is the only case were it is not possible to cast between a SysHandleType value and a SysSocketType value. This is why it is recommended to always use getHandle() when a SysHandleType is required and getSocket() when a SysSocketType is required.
A subclass which uses file descriptors or device handles for read, write, or both, must override the methods getReadHandle(), getWriteHandle(), or both. If the two types of operations use the same file descriptor, the two methods must return the same value.
An application should call getReadHandle() for read operations and getWriteHandle() for write operations. The method getHandle() returns getReadHandle() if its returns a valid value, and getWriteHandle() otherwise.
|
inherited |
Get the underlying file descriptor or device handle as a system socket handle.
|
inherited |
Get the underlying file descriptor or device handle as a system socket handle for read operations.
|
inherited |
Get the underlying file descriptor or device handle as a system socket handle for write operations.
|
protectedinherited |
Check the blocking mode of a device.
Called by subclass methods which are explicitly called in blocking or non-blocking mode.
| [in] | non_blocking | The required non-blocking mode. |
| [in] | opname | Name of the operation, for the error message. |
|
protectedinherited |
Check the blocking mode of a device.
Called by subclass methods which are explicitly called in blocking or non-blocking mode.
| [in,out] | iosb | Address 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] | opname | Name of the operation, for the error message. |
|
protectedinherited |
Low-level method to set the system file or socket descriptor in non-blocking mode.
| [in] | non_blocking | It true, the device is set in non-blocking mode. |
Summary: Do not use this method unless you exactly know what you are doing.
UNIX: Depending on the way a file descriptor is created, it may be possible to specify the non-blocking mode from the beginning. Or it can be somehow inherited. However, this is not portable.
Examples:
In all cases, it is possible to set a file descriptor in non-blocking mode at any time using the method setSystemNonBlocking(). This method uses fcntl(F_SETFL) to alter the file descriptor's flags.
Windows: The natural way of not being blocked on I/O on Windows is asynchronous I/O. To increase the general confusion, there is some form of non-blocking mode on Windows sockets, and only sockets, not other forms of file handles. This mode is activated using "ioctlsocket(fd, FIONBIO, &mode)". When this mode is active, socket I/O become similar to UNIX: they immediately either succeed or fail, but never block. However, there is no way to get notified when the I/O becomes possible. There is no equivalent to epoll (Linux) or kqueue (macOS and BSD). The Windows I/O Completion Ports can only work on asynchronous I/O, using OVERLAPPED structures. Because this form of non-blocking mode is mostly useless in practice, we do not use it and the method setSystemNonBlocking() does nothing on Windows.
|
protectedinherited |
Generic system write operation.
This is a convenience method which can be used (or not) by subclasses when the system calls write() (UNIX) or WriteFile() (Windows) are appropriate.
| [in] | addr | Address of the data to write. |
| [in] | size | Size in bytes of the data to write. |
| [out] | written_size | Actually written size in bytes. Can be less than size in case of error in the middle of the write. |
| [in,out] | iosb | Address of an IOSB structure. If non-null, the stream must be in non-blocking mode. When null, the stream must be in blocking mode (the default). See the description of ts::NonBlockingDevice::IOSB. |
| [in] | position | This value is only used on Windows with asynchronous I/O on disk file. On Windows, when asynchronous I/O are used on random access files, the file position is not maintained. Each read or write operation is performed at the specified absolute position. |
|
protectedinherited |
Generic system read operation.
This is a convenience method which can be used (or not) by subclasses when the system calls read() (UNIX) or ReadFile() (Windows) are appropriate.
| [out] | addr | Address of the buffer for the incoming data. |
| [in] | max_size | Maximum size in bytes of the buffer. |
| [out] | ret_size | Returned input size in bytes. If zero, end of file has been reached or an error occurred. |
| [in] | abort | If non-zero, invoked when I/O is interrupted (in case of user-interrupt, return, otherwise retry). |
| [in,out] | iosb | Address of an IOSB structure. If non-null, the stream must be in non-blocking mode. When null, the stream must be in blocking mode (the default). See the description of ts::NonBlockingDevice::IOSB. |
| [in] | position | This value is only used on Windows with asynchronous I/O on disk file. On Windows, when asynchronous I/O are used on random access files, the file position is not maintained. Each read or write operation is performed at the specified absolute position. |
|
overridevirtualinherited |
Access the Report which is associated with this object.
Can be called from another thread only if the Report object is thread-safe.
Implements ts::ReporterInterface.
Associate this object with another Report to log errors.
| [in] | report | Where 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. |
|
inherited |
Associate this object with another ReporterBase to log errors.
| [in] | delegate | Use the report of another ReporterBase. If delegate is null, the previous explicit Report is used.. |
|
inherited |
Temporarily mute the associated report.
| [in] | mute | It true, report() will return a null report (log messages are discarded), until muteReport() is invoked again with mute set to false. |
|
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.
| [in] | silent | If true, do not report errors, report debug messages instead. |
| [in] | default_severity | Default severity, in non-silent mode (error by default). |
|
inherited |
|
inherited |
|
inlineprotectedinherited |
Call a handler on all subscribers, using a lambda expression.
| [in] | func | Function to call as lambda expression. |