TSDuck v3.40-4033
MPEG Transport Stream Toolkit
Loading...
Searching...
No Matches
ts::Socket Class Referenceabstract

Base class for TCP and UDP sockets. More...

#include <tsSocket.h>

Inheritance diagram for ts::Socket:

Public Member Functions

 Socket ()=default
 Constructor.
 
virtual ~Socket ()
 Destructor.
 
virtual bool close (Report &report=(ts::CerrReport::Instance()))
 Close the socket.
 
IP generation () const
 Get the IP generation with which the socket was open.
 
bool getLocalAddress (IPSocketAddress &addr, Report &report=(ts::CerrReport::Instance()))
 Get local socket address.
 
SysSocketType getSocket () const
 Get the underlying socket device handle (use with care).
 
bool isOpen () const
 Check if socket is open.
 
virtual bool open (IP gen, Report &report=(ts::CerrReport::Instance()))=0
 Open the socket.
 
bool reusePort (bool reuse_port, Report &report=(ts::CerrReport::Instance()))
 Set the "reuse port" option.
 
bool setReceiveBufferSize (size_t size, Report &report=(ts::CerrReport::Instance()))
 Set the receive buffer size.
 
bool setReceiveTimeout (cn::milliseconds timeout, Report &report=(ts::CerrReport::Instance()))
 Set the receive timeout.
 
bool setSendBufferSize (size_t size, Report &report=(ts::CerrReport::Instance()))
 Set the send buffer size.
 

Protected Member Functions

bool convert (IPAddress &addr, Report &report) const
 Convert an IP address to make it compatible with the socket IP generation.
 
bool createSocket (IP gen, int type, int protocol, Report &report)
 Create the socket.
 
virtual void declareOpened (SysSocketType sock, Report &report)
 Set an open socket descriptor from a subclass.
 

Detailed Description

Base class for TCP and UDP sockets.

Member Function Documentation

◆ open()

virtual bool ts::Socket::open ( IP  gen,
Report report = (ts::CerrReport::Instance()) 
)
pure virtual

Open the socket.

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

Implemented in ts::TCPSocket, ts::UDPReceiver, and ts::UDPSocket.

◆ close()

virtual bool ts::Socket::close ( Report report = (ts::CerrReport::Instance()))
virtual

Close the socket.

Parameters
[in,out]reportWhere to report error.
Returns
True on success, false on error.

Reimplemented in ts::TCPServer, ts::TCPSocket, and ts::UDPSocket.

◆ isOpen()

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

Check if socket is open.

Returns
True if socket is open.

◆ generation()

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

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,
Report report = (ts::CerrReport::Instance()) 
)

Set the send buffer size.

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

◆ setReceiveBufferSize()

bool ts::Socket::setReceiveBufferSize ( size_t  size,
Report report = (ts::CerrReport::Instance()) 
)

Set the receive buffer size.

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

◆ setReceiveTimeout()

bool ts::Socket::setReceiveTimeout ( cn::milliseconds  timeout,
Report report = (ts::CerrReport::Instance()) 
)

Set the receive timeout.

Parameters
[in]timeoutReceive timeout in milliseconds. If negative, receive timeout is not used.
[in,out]reportWhere to report error.
Returns
True on success, false on error.

◆ reusePort()

bool ts::Socket::reusePort ( bool  reuse_port,
Report report = (ts::CerrReport::Instance()) 
)

Set the "reuse port" option.

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

◆ getLocalAddress()

bool ts::Socket::getLocalAddress ( IPSocketAddress addr,
Report report = (ts::CerrReport::Instance()) 
)

Get local socket address.

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

◆ getSocket()

SysSocketType ts::Socket::getSocket ( ) const
inline

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.

◆ createSocket()

bool ts::Socket::createSocket ( IP  gen,
int  type,
int  protocol,
Report report 
)
protected

Create the socket.

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

◆ declareOpened()

virtual void ts::Socket::declareOpened ( SysSocketType  sock,
Report report 
)
protectedvirtual

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.
[in,out]reportWhere to report error.

Reimplemented in ts::TCPSocket.

◆ convert()

bool ts::Socket::convert ( IPAddress addr,
Report report 
) const
protected

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

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

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