libptpmgmt  1.4
libptpmgmt library that provides the functionality of linuxptp pmc
Protected Member Functions | List of all members
SockBase Class Reference

Base class for all sockets. More...

#include <sock.h>

Inheritance diagram for SockBase:
Inheritance graph
[legend]

Protected Member Functions

void close ()
 
bool init ()
 
bool send (const void *msg, size_t len)
 
bool send (Buf &buf, size_t len)
 
bool sendBuf (Buf &buf, size_t len)
 
ssize_t rcv (void *buf, size_t bufSize, bool block=false)
 
ssize_t rcv (Buf &buf, bool block=false)
 
ssize_t rcvBuf (Buf &buf, bool block=false)
 
int getFd () const
 
int fileno () const
 
bool poll (uint64_t timeout_ms=0) const
 
bool tpoll (uint64_t &timeout_ms) const
 

Detailed Description

Base class for all sockets.

provide functions that are supported by all socket's classes

Member Function Documentation

◆ close()

void SockBase::close ( )
inlineprotected

< close socket and release its resources

◆ fileno()

int SockBase::fileno ( ) const
inlineprotected

Get socket file description

Returns
socket file description
Note
Can be used to poll, send or receive from socket. The user is advice to use properly. Do NOT free the socket. If you want to close the socket use the close function ONLY.

◆ getFd()

int SockBase::getFd ( ) const
inlineprotected

Get socket file description

Returns
socket file description
Note
Can be used to poll, send or receive from socket. The user is advice to use properly. Do NOT free the socket. If you want to close the socket use the close function ONLY.

◆ init()

bool SockBase::init ( )
inlineprotected

Allocate the socket and initialize it with current parameters

Returns
true if socket creation success

◆ poll()

bool SockBase::poll ( uint64_t  timeout_ms = 0) const
protected

Single socket polling

Parameters
[in]timeout_mstimeout in milliseconds, until receive a packet. use 0 for blocking.
Returns
true if a packet is ready for receive
Note
If user need multiple socket, then fetch the file description with fileno() And implement it, or merge it into an existing polling
Python: when building with 'PY_USE_S_THRD' using Python 'Global Interpreter Lock'. Which use mutex on all library functions. So this function can block other threads. In this case, user may prefer native Python select module.

◆ rcv() [1/2]

ssize_t SockBase::rcv ( Buf buf,
bool  block = false 
)
inlineprotected

Receive a message using the socket

Parameters
[in,out]bufobject with message memory buffer
[in]blocktrue, wait till a packet arrives. false, do not wait, return error if no packet available
Returns
number of bytes received or negative on failure

◆ rcv() [2/2]

ssize_t SockBase::rcv ( void *  buf,
size_t  bufSize,
bool  block = false 
)
inlineprotected

Receive a message using the socket

Parameters
[in,out]bufpointer to a memory buffer
[in]bufSizememory buffer size
[in]blocktrue, wait till a packet arrives. false, do not wait, return error if no packet available
Returns
number of bytes received or negative on failure

◆ rcvBuf()

ssize_t SockBase::rcvBuf ( Buf buf,
bool  block = false 
)
inlineprotected

Receive a message using the socket

Parameters
[in,out]bufobject with message memory buffer
[in]blocktrue, wait till a packet arrives. false, do not wait, return error if no packet available
Returns
number of bytes received or negative on failure
Note
identical to rcv. Some scripts fail to match proper function

◆ send() [1/2]

bool SockBase::send ( Buf buf,
size_t  len 
)
inlineprotected

Send the message using the socket

Parameters
[in]bufobject with message memory buffer
[in]lenmessage length
Returns
true if message is sent
Note
true does NOT guarantee the frame was successfully arrives its target. Only the network layer sends it.

◆ send() [2/2]

bool SockBase::send ( const void *  msg,
size_t  len 
)
inlineprotected

Send the message using the socket

Parameters
[in]msgpointer to message memory buffer
[in]lenmessage length
Returns
true if message is sent
Note
true does NOT guarantee the frame was successfully arrives its target. Only the network layer sends it.

◆ sendBuf()

bool SockBase::sendBuf ( Buf buf,
size_t  len 
)
inlineprotected

Send the message using the socket

Parameters
[in]bufobject with message memory buffer
[in]lenmessage length
Returns
true if message is sent
Note
true does NOT guarantee the frame was successfully arrives its target. Only the network layer sends it.
identical to send. Some scripts fail to match proper function

◆ tpoll()

bool SockBase::tpoll ( uint64_t &  timeout_ms) const
protected

Single socket polling and update timeout

Parameters
[in,out]timeout_mstimeout in milliseconds until receive a packet. use 0 for blocking.
Returns
true if a packet is ready for receive
Note
The function will reduce the wait time from timeout when packet arrives. The user is advice to ensure the timeout is positive, as zero cause to block until receive a packet.
If user need multiple socket, then fetch the file description with fileno() And implement it, or merge it into an existing polling
Python: when building with 'PY_USE_S_THRD' using Python 'Global Interpreter Lock'. Which use mutex on all library functions. So this function can block other threads. In this case, user may prefer native Python select module.

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