TSDuck v3.46-4930
MPEG Transport Stream Toolkit
Loading...
Searching...
No Matches
ts::TLSServer Class Reference

#include <tsTLSServer.h>

Inheritance diagram for ts::TLSServer:
Collaboration diagram for ts::TLSServer:

Public Types

using SuperClass = TCPSocket

Public Member Functions

 TLSServer (Report *report)
 TLSServer (Report *report, const TLSArgs &args)
 TLSServer (ReporterBase *delegate)
 TLSServer (ReporterBase *delegate, const TLSArgs &args)
virtual bool accept (TCPConnection &client, IPSocketAddress &addr, IOSB *=nullptr) override
void addSubscription (SubscriptionHandlerInterface *handler)
bool bind (const IPSocketAddress &addr)
void cancelSubscription (SubscriptionHandlerInterface *handler)
virtual bool close (bool silent=false) final
IP generation () const
const UString & getCertificatePath () const
const UString & getCertificateStore () const
size_t getEphemeralRSABits () const
SysHandleType getHandle () const
const UString & getKeyPath () const
bool getLocalAddress (IPSocketAddress &addr) const
virtual SysHandleType getReadHandle () const override
SysSocketType getReadSocket () const
SysSocketType getSocket () const
virtual SysHandleType getWriteHandle () const override
SysSocketType getWriteSocket () const
bool isNonBlocking () const
bool isOpen () const
bool isSupportedByReactor (bool recheck=false)
virtual bool listen (int backlog) override
UString localName ()
bool muteReport (bool mute)
virtual bool open (IP gen=IP::Any) final
virtual Report & report () const override
bool reusePort (bool reuse_port)
bool setAcceptStatus (TCPConnection &client, IPSocketAddress &client_address, IOSB *iosb)
void setArgs (const TLSArgs &args)
void setCertificatePath (const UString &path)
void setCertificateStore (const UString &name)
void setEphemeralRSABits (size_t bits)
bool setKeepAlive (bool active)
void setKeyPath (const UString &path)
bool setLingerTime (int seconds)
bool setNoDelay (bool active)
bool setNoLinger ()
bool setNonBlocking (bool non_blocking)
bool setReceiveBufferSize (size_t size)
bool setReceiveTimeout (cn::milliseconds timeout)
Report * setReport (Report *report)
ReporterBase * setReport (ReporterBase *delegate)
bool setSendBufferSize (size_t size)
bool setTTL (int ttl)

Static Public Member Functions

static bool IsPendingStatus (int error_code)
static int SilentLevel (bool silent, int default_severity=Severity::Error)

Static Public Attributes

static constexpr size_t DEFAULT_RECEIVE_BUFFER_SIZE = 16 * 1024
static constexpr size_t DEFAULT_RSA_BITS = 3072

Protected Member Functions

virtual bool allowSetNonBlocking () const override
template<typename HANDLER, typename F>
requires std::derived_from<HANDLER, SubscriptionHandlerInterface>
void callSubscribers (F &&func)
bool checkNonBlocking (bool non_blocking, const UChar *opname)
bool checkNonBlocking (IOSB *iosb, const UChar *opname)
virtual bool closeImplementation (bool silent) override
bool convert (IPAddress &addr) const
bool createSocket (IP gen, int type, int protocol)
virtual void declareOpened (SysSocketType sock) override
int genericSystemRead (void *addr, size_t max_size, size_t &ret_size, const AbortInterface *abort, Device::IOSB *iosb, uint64_t position)
int genericSystemWrite (const void *addr, size_t size, size_t &written_size, Device::IOSB *iosb, uint64_t position)
virtual bool openImplementation (IP gen) override
bool setSystemNonBlocking (bool non_blocking)

Protected Attributes

std::recursive_mutex _mutex {}
 Mutex protecting this object.

Detailed Description

Implementation of a SSL/TLS server.

Creating a test private key and its self-signed certificate

On UNIX systems (with OpenSSL):

openssl req -quiet -newkey rsa:3072 -new -noenc -x509 -subj="/CN=$(hostname)" -days 3650 -keyout key.pem -out cert.pem

To display the properties of the certificate:

openssl x509 -in cert.pem -noout -text

On Windows:

New-SelfSignedCertificate -FriendlyName "Test Server" -Type SSLServerAuthentication `
-DnsName @([System.Net.Dns]::GetHostName(), "localhost") `
-CertStoreLocation Cert:\CurrentUser\My `
-KeyAlgorithm "RSA" -KeyLength 3072

To display the properties of the certificate:

Get-ChildItem Cert:\CurrentUser\My | Where-Object -Property FriendlyName -eq "Test Server" | Format-List
Definition tsObject.h:36

A self-signed certificate is considered as invalid. So, make sure to ignore this error. With curl, use option –insecure or -k.

To view the certificate of a server using OpenSSL:

openssl s_client -showcerts -servername <name> -connect <name>:<port> </dev/null | openssl x509 -noout -text

Member Typedef Documentation

◆ SuperClass

Reference to the superclass.

Constructor & Destructor Documentation

◆ TLSServer() [1/4]

ts::TLSServer::TLSServer ( Report * report)
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.

◆ TLSServer() [2/4]

ts::TLSServer::TLSServer ( ReporterBase * delegate)
explicit

Constructor.

Parameters
[in]delegateUse the report of another ReporterBase. If delegate is null, log messages are discarded.

◆ TLSServer() [3/4]

ts::TLSServer::TLSServer ( Report * report,
const TLSArgs & args )
inline

Constructor with initial arguments.

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]argsInitial TLS arguments.

◆ TLSServer() [4/4]

ts::TLSServer::TLSServer ( ReporterBase * delegate,
const TLSArgs & args )
inline

Constructor with initial arguments.

Parameters
[in]delegateUse the report of another ReporterBase. If delegate is null, log messages are discarded.
[in]argsInitial TLS arguments.

Member Function Documentation

◆ listen()

virtual bool ts::TLSServer::listen ( int backlog)
overridevirtual

Start the server.

Here, starting the server means starting to listen to incoming client connections. Internally to the kernel, the incoming connections are queued up to backlog. When the method accept() is invoked and some incoming connections are already queued in the kernel, the oldest one is immediately accepted. Otherwise, accept() blocks until a new incoming connection arrives.

Parameters
[in]backlogMaximum number of incoming connections which allowed to queue in the kernel until the next call to accept(). Note that this value is a minimum queue size. But the kernel may accept more. There is no guarantee that additional incoming connections will be rejected if more than backlog are already queueing.
Returns
True on success, false on error.

Reimplemented from ts::TCPServer.

◆ accept()

virtual bool ts::TLSServer::accept ( TCPConnection & client,
IPSocketAddress & client_address,
IOSB * iosb = nullptr )
overridevirtual

Wait for an incoming client connection.

Parameters
[out]clientThis object receives the new connection. Upon successful return from accept(), the TCPConnection object is a properly connected TCP session. Once the connection is completed, the TCPConnection objects on the client side and the server side are symmetric and can be used the same way. In case of asynchronous I/O, the object must remain valid until the accept() completes or is canceled.
[out]client_addressThis object receives the socket address of the client. If the server wants to filter client connections based on their IP address, it may use addr for that.
[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. In case of non-blocking mode, if the accept is successfully started but still pending (no available client), iosb->pending is set to true and the method returns true.
See also
listen()

Reimplemented from ts::TCPServer.

◆ closeImplementation()

virtual bool ts::TLSServer::closeImplementation ( bool silent)
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().

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::TCPServer.

◆ setAcceptStatus()

bool ts::TCPServer::setAcceptStatus ( TCPConnection & client,
IPSocketAddress & client_address,
IOSB * iosb )
inherited

Update the status of an asynchronous accept(). 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]clientThe socket which received the new connection.
[out]client_addressThis object receives the socket address of the client.
[in,out]iosbAddress of the IOSB structure which was used when connect() was called.
Returns
True on success, false on error.

◆ setTTL()

bool ts::TCPSocket::setTTL ( int ttl)
inherited

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.
Returns
True on success, false on error.

◆ setNoLinger()

bool ts::TCPSocket::setNoLinger ( )
inherited

Remove the linger time option.

Returns
True on success, false on error.

◆ setLingerTime()

bool ts::TCPSocket::setLingerTime ( int seconds)
inherited

Set the linger time option.

Parameters
[in]secondsNumber of seconds to wait after shuting down the socket.
Returns
True on success, false on error.

◆ setKeepAlive()

bool ts::TCPSocket::setKeepAlive ( bool active)
inherited

Set the "keep alive" option.

Parameters
[in]activeIf true, the socket periodically sends "keep alive" packets when the connection is idle.
Returns
True on success, false on error.

◆ setNoDelay()

bool ts::TCPSocket::setNoDelay ( bool active)
inherited

Set the "no delay" option.

Parameters
[in]activeIf true, the socket immediately sends outgoing packets. By default, a TCP socket waits a small amount of time after a send() operation to get a chance to group outgoing data from successive send() operations into one single packet.
Returns
True on success, false on error.

◆ openImplementation()

virtual bool ts::TCPSocket::openImplementation ( IP gen)
overrideprotectedvirtualinherited

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.

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.

◆ declareOpened()

virtual void ts::TCPSocket::declareOpened ( SysSocketType sock)
overrideprotectedvirtualinherited

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 from ts::Socket.

◆ open()

virtual bool ts::Socket::open ( IP gen = IP::Any)
finalvirtualinherited

Open the socket. Subclasses are not permitted to override this one, they should implement openImplementation().

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.

◆ close()

virtual bool ts::Socket::close ( bool silent = false)
finalvirtualinherited

Close the socket. Subclasses are not permitted to override this one, they should implement closeImplementation().

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.

◆ 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.

◆ localName()

UString ts::Socket::localName ( )
inherited

Get the local address as a string.

Returns
A string representation of the IP address and port of the socket.

◆ getReadHandle()

virtual SysHandleType ts::Socket::getReadHandle ( ) const
overridevirtualinherited

Get the underlying file descriptor or device handle for read operations. Subclasses should override this method.

Returns
The underlying file descriptor for read operations or SYS_HANDLE_INVALID if the device is not open for read.
See also
getHandle()

Reimplemented from ts::Device.

◆ getWriteHandle()

virtual SysHandleType ts::Socket::getWriteHandle ( ) const
overridevirtualinherited

Get the underlying file descriptor or device handle for write operations. Subclasses should override this method.

Returns
The underlying file descriptor for write operations or SYS_HANDLE_INVALID if the device is not open for write.
See also
getHandle()

Reimplemented from ts::Device.

◆ 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&)

◆ 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::Device.

◆ setNonBlocking()

bool ts::Device::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::Device::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()

◆ isSupportedByReactor()

bool ts::Device::isSupportedByReactor ( bool recheck = false)
inherited

Check if the device is supported by a reactor for non-blocking or asynchronous I/O.

Parameters
[in]recheckIf true, force a recheck. If false and the device was previously checked, return the previous cached value.
Returns
True if the device is supported by a reactor for non-blocking or asynchronous I/O, false otherwise.

◆ IsPendingStatus()

bool ts::Device::IsPendingStatus ( int error_code)
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).

Parameters
[in]error_codeSystem error code.
Returns
True if error_code is an in-progress/would-block one.

◆ getHandle()

SysHandleType ts::Device::getHandle ( ) const
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.

Returns
The underlying file descriptor or device handler. Return SYS_HANDLE_INVALID if the socket is not open.

◆ getSocket()

SysSocketType ts::Device::getSocket ( ) const
inherited

Get the underlying file descriptor or device handle as a system socket handle.

Returns
The underlying socket descriptor. Return SYS_SOCKET_INVALID if the socket is not open.
See also
getHandle()

◆ getReadSocket()

SysSocketType ts::Device::getReadSocket ( ) const
inherited

Get the underlying file descriptor or device handle as a system socket handle for read operations.

Returns
The underlying file descriptor for read operations or SYS_SOCKET_INVALID if the socket is not open for read.
See also
getHandle()

◆ getWriteSocket()

SysSocketType ts::Device::getWriteSocket ( ) const
inherited

Get the underlying file descriptor or device handle as a system socket handle for write operations.

Returns
The underlying file descriptor for read operations or SYS_SOCKET_INVALID if the socket is not open for write.
See also
getHandle()

◆ checkNonBlocking() [1/2]

bool ts::Device::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::Device::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::Device::setSystemNonBlocking ( bool non_blocking)
protectedinherited

Low-level method to set the system file or socket descriptor in non-blocking mode.

Parameters
[in]non_blockingIt true, the device is set in non-blocking mode.
Returns
True on success, false on error.

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:

  • On Linux and FreeBSD, a socket can be directly created in non-blocking mode using the flag SOCK_NONBLOCK in the 'type' parameter of the socket() system call. However, it does not work on macOS.
  • On macOS (and maybe FreeBSD), when a server socket is in non-blocking mode, all client session sockets which are created by accept() are also in non-blocking mode. However, on Linux, they are in blocking mode.

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.

See also
https://learn.microsoft.com/en-us/archive/blogs/csliu/io-concept-blockingnon-blocking-vs-syncasync

◆ genericSystemWrite()

int ts::Device::genericSystemWrite ( const void * addr,
size_t size,
size_t & written_size,
Device::IOSB * iosb,
uint64_t position )
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.

Parameters
[in]addrAddress of the data to write.
[in]sizeSize in bytes of the data to write.
[out]written_sizeActually written size in bytes. Can be less than size in case of error in the middle of the write.
[in,out]iosbAddress 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::Device::IOSB.
[in]positionThis 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.
Returns
Error code. When the I/O is non-blocking/asynchronous and pending, return SYS_SUCCESS and iosb->pending is true. Return SYS_EOF when it is no longer possible to write (e.g. broken pipe).

◆ genericSystemRead()

int ts::Device::genericSystemRead ( void * addr,
size_t max_size,
size_t & ret_size,
const AbortInterface * abort,
Device::IOSB * iosb,
uint64_t 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.

Parameters
[out]addrAddress of the buffer for the incoming data.
[in]max_sizeMaximum size in bytes of the buffer.
[out]ret_sizeReturned input size in bytes. If zero, end of file has been reached or an error occurred.
[in]abortIf non-zero, invoked when I/O is interrupted (in case of user-interrupt, return, otherwise retry).
[in,out]iosbAddress 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::Device::IOSB.
[in]positionThis 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.
Returns
Error code. When the I/O is non-blocking/asynchronous and pending, return SYS_SUCCESS and iosb->pending is true. Return SYS_EOF when it is no longer possible to read.

◆ report()

virtual Report & ts::ReporterBase::report ( ) const
overridevirtualinherited

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.

Implements ts::ReporterInterface.

◆ 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()

int ts::ReporterBase::SilentLevel ( bool silent,
int default_severity = Severity::Error )
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.
[in]default_severityDefault severity, in non-silent mode (error by default).
Returns
Error when silent is false, Debug otherwise.

◆ addSubscription()

void ts::SubscriptionBase::addSubscription ( SubscriptionHandlerInterface * handler)
inherited

Add a subscriber to open/close events.

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

◆ cancelSubscription()

void ts::SubscriptionBase::cancelSubscription ( SubscriptionHandlerInterface * handler)
inherited

Remove a subscriber to open/close events.

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

◆ callSubscribers()

template<typename HANDLER, typename F>
requires std::derived_from<HANDLER, SubscriptionHandlerInterface>
void ts::SubscriptionBase::callSubscribers ( F && func)
inlineprotectedinherited

Call a handler on all subscribers, using a lambda expression.

Parameters
[in]funcFunction to call as lambda expression.

◆ setArgs()

void ts::TLSServerBase::setArgs ( const TLSArgs & args)
inlineinherited

Set command line arguments for the server.

Parameters
[in]argsTLS arguments.

◆ setCertificatePath()

void ts::TLSServerBase::setCertificatePath ( const UString & path)
inlineinherited

Set the certificate path for the server.

Parameters
[in]pathPath to the certificate.
  • On UNIX systems (with OpenSSL), this is the path name of the certificate file in PEM format.
  • On Windows, this is the name of a certificate, either its "friendly name", its subject name (without "CN="), its DNS name.

◆ getCertificatePath()

const UString & ts::TLSServerBase::getCertificatePath ( ) const
inlineinherited

Get the certificate path for the server.

Returns
A constant reference to the path to the certificate.
See also
setCertificatePath()

◆ setKeyPath()

void ts::TLSServerBase::setKeyPath ( const UString & path)
inlineinherited

Set the private key path for the server.

Parameters
[in]pathPath to the private key.
  • On UNIX systems (with OpenSSL), this is the path name of the private key file in PEM format.
  • On Windows, the private key is retrieved with the certificate and this parameter is unused.

◆ getKeyPath()

const UString & ts::TLSServerBase::getKeyPath ( ) const
inlineinherited

Get the private key path for the server.

Returns
A constant reference to the path to the private key.
See also
setKeyPath()

◆ setCertificateStore()

void ts::TLSServerBase::setCertificateStore ( const UString & name)
inlineinherited

Set the certificate store.

Parameters
[in]name
  • On UNIX systems (with OpenSSL), this parameter is unused.
  • On Windows, the possible values are "system" (Cert:\LocalMachine\My) and "user" (Cert:\CurrentUser\My). The default is "user".

◆ getCertificateStore()

const UString & ts::TLSServerBase::getCertificateStore ( ) const
inlineinherited

Get the certificate store.

Returns
A constant reference to the name of the certificate store.
See also
setCertificateStore()

◆ setEphemeralRSABits()

void ts::TLSServerBase::setEphemeralRSABits ( size_t bits)
inlineinherited

Specify to use an ephemeral self-signed certificate with an ephemeral RSA key of the specified size.

Parameters
[in]bitsSize in bits of the ephemeral RSA key. When set to zero, no ephemeral self-signed certificate is used and a persistent certificate must be used.

◆ getEphemeralRSABits()

size_t ts::TLSServerBase::getEphemeralRSABits ( ) const
inherited

Get the size in bits of the ephemeral RSA key which is used for the ephemeral self-signed certificate.

Returns
Size in bits of the ephemeral RSA key. When zero, no ephemeral self-signed certificate is used.

Member Data Documentation

◆ DEFAULT_RECEIVE_BUFFER_SIZE

size_t ts::Device::DEFAULT_RECEIVE_BUFFER_SIZE = 16 * 1024
staticconstexprinherited

Default buffer size for receive operations. This constant is used as default value in several I/O classes.

◆ DEFAULT_RSA_BITS

size_t ts::TLSServerBase::DEFAULT_RSA_BITS = 3072
staticconstexprinherited

Default key size in bits of ephemeral RSA keys when no certificate is specified.

When no parameter specifies how the certificate shall be retrieved or generated, a default ephemeral self-signed certificate is generated using a random RSA key of that size.


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