TSDuck v3.38-3703
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.
 
bool getLocalAddress (IPv4SocketAddress &addr, Report &report=(ts::CerrReport::Instance()))
 Get local socket address.
 
SysSocketType getSocket () const
 Get the underlying socket device handle (use with care).
 
bool isOpen () const
 Check if socket is open.
 
virtual bool open (Report &report=(ts::CerrReport::Instance()))=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 createSocket (int domain, int type, int protocol, Report &report)
 Create the socket.
 
virtual void declareOpened (SysSocketType sock, Report &report)
 Set an open socket descriptor from a subclass.
 

Detailed Description

Base class for TCP and UDP sockets.

Member Function Documentation

◆ open()

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

Open the socket.

Parameters
[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.

◆ 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 ( IPv4SocketAddress 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 ( int  domain,
int  type,
int  protocol,
Report report 
)
protected

Create the socket.

Parameters
[in]domainSocket domain: PF_INET
[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.

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


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