libptpmgmt  1.4
libptpmgmt library that provides the functionality of linuxptp pmc
Public Member Functions | Static Public Member Functions | List of all members
SockUnix Class Reference

Unix socket. More...

#include <sock.h>

Inheritance diagram for SockUnix:
Inheritance graph
[legend]
Collaboration diagram for SockUnix:
Collaboration graph
[legend]

Public Member Functions

 SockUnix ()
 
const std::string & getPeerAddress () const
 
const char * getPeerAddress_c () const
 
bool isPeerAddressAbstract () const
 
bool setPeerAddress (const std::string &string, bool useAbstract=false)
 
bool setPeerAddress (const ConfigFile &cfg, const std::string &section="")
 
const std::string & getSelfAddress () const
 
const char * getSelfAddress_c () const
 
bool isSelfAddressAbstract () const
 
bool setSelfAddress (const std::string &string)
 
bool setSelfAddress (const std::string &string, bool useAbstract)
 
bool setDefSelfAddress (const std::string &rootBase="", const std::string &useDef="")
 
const std::string & getHomeDir ()
 
const char * getHomeDir_c ()
 
bool sendTo (const void *msg, size_t len, const std::string &addrStr) const
 
bool sendTo (const void *msg, size_t len, const std::string &addrStr, bool useAbstract) const
 
bool sendTo (Buf &buf, size_t len, const std::string &addrStr, bool useAbstract=false) const
 
ssize_t rcvFrom (void *buf, size_t bufSize, std::string &from, bool block=false) const
 
ssize_t rcvFrom (Buf &buf, std::string &from, bool block=false) const
 
ssize_t rcvFrom (void *buf, size_t bufSize, bool block=false)
 
ssize_t rcvFrom (Buf &buf, bool block=false)
 
ssize_t rcvBufFrom (Buf &buf, bool block=false)
 
const std::string & getLastFrom () const
 
const char * getLastFrom_c () const
 
bool isLastFromAbstract () const
 

Static Public Member Functions

static bool isAddressAbstract (const std::string &addr)
 

Additional Inherited Members

- Protected Member Functions inherited from SockBase
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

Unix socket.

provide Unix socket that can be used to communicate with linuxptp daemon, ptp4l.

Constructor & Destructor Documentation

◆ SockUnix()

SockUnix::SockUnix ( )
inline

<

Member Function Documentation

◆ getHomeDir()

const std::string& SockUnix::getHomeDir ( )

Get user home directory

Returns
string object with home directory

◆ getHomeDir_c()

const char* SockUnix::getHomeDir_c ( )

Get user home directory

Returns
string with home directory

◆ getLastFrom()

const std::string& SockUnix::getLastFrom ( ) const
inline

Fetch origin address from last rcvFrom() call

Returns
Unix socket address
Note
store address only on the rcvFrom() call without the from parameter
Attention
no protection or thread safe, fetch last rcvFrom() call with this object.

◆ getLastFrom_c()

const char* SockUnix::getLastFrom_c ( ) const
inline

Fetch origin address from last rcvFrom() call

Returns
Unix socket address
Note
store address only on the rcvFrom() call without the from parameter
Attention
no protection or thread safe, fetch last rcvFrom() call with this object.

◆ getPeerAddress()

const std::string& SockUnix::getPeerAddress ( ) const
inline

Get peer address

Returns
string object with peer address

◆ getPeerAddress_c()

const char* SockUnix::getPeerAddress_c ( ) const
inline

Get peer address

Returns
string with peer address

◆ getSelfAddress()

const std::string& SockUnix::getSelfAddress ( ) const
inline

Get self address

Returns
string object with self address

◆ getSelfAddress_c()

const char* SockUnix::getSelfAddress_c ( ) const
inline

Get self address

Returns
string with self address

◆ isAddressAbstract()

static bool SockUnix::isAddressAbstract ( const std::string &  addr)
inlinestatic

Is address abstract?

Parameters
[in]addrsocket address
Returns
true if address is abstract address

◆ isLastFromAbstract()

bool SockUnix::isLastFromAbstract ( ) const
inline

Is last from address abstract?

Returns
true if last from address is abstract address

◆ isPeerAddressAbstract()

bool SockUnix::isPeerAddressAbstract ( ) const
inline

Is peer address abstract?

Returns
true if peer address is abstract address

◆ isSelfAddressAbstract()

bool SockUnix::isSelfAddressAbstract ( ) const
inline

Is self address abstract?

Returns
true if self address is abstract address

◆ rcvBufFrom()

ssize_t SockUnix::rcvBufFrom ( Buf buf,
bool  block = false 
)
inline

Receive a message using the socket from any address

Parameters
[in]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
use getLastFrom() to fetch origin address which send the packet
identical to rcvFrom(). Some scripts fail to match proper function.

◆ rcvFrom() [1/4]

ssize_t SockUnix::rcvFrom ( Buf buf,
bool  block = false 
)
inline

Receive a message using the socket from any address

Parameters
[in]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
use getLastFrom() to fetch origin address which send the packet

◆ rcvFrom() [2/4]

ssize_t SockUnix::rcvFrom ( Buf buf,
std::string &  from,
bool  block = false 
) const
inline

Receive a message using the socket from any address

Parameters
[in]bufobject with message memory buffer
[out]fromUnix socket address (socket file)
[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
from store the origin address which send the packet

◆ rcvFrom() [3/4]

ssize_t SockUnix::rcvFrom ( void *  buf,
size_t  bufSize,
bool  block = false 
)
inline

Receive a message using the socket from any address

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
Note
use getLastFrom() to fetch origin address which send the packet

◆ rcvFrom() [4/4]

ssize_t SockUnix::rcvFrom ( void *  buf,
size_t  bufSize,
std::string &  from,
bool  block = false 
) const

Receive a message using the socket from any address

Parameters
[in,out]bufpointer to a memory buffer
[in]bufSizememory buffer size
[out]fromUnix socket address (socket file)
[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
from store the origin address which send the packet

◆ sendTo() [1/3]

bool SockUnix::sendTo ( Buf buf,
size_t  len,
const std::string &  addrStr,
bool  useAbstract = false 
) const
inline

Send the message using the socket to a specific address

Parameters
[in]bufobject with message memory buffer
[in]lenmessage length
[in]addrStrUnix socket address (socket file)
[in]useAbstractuse Abstract socket address
Returns
true if message is sent
Note
true does NOT guarantee the frame was successfully arrives its target. Only the network layer sends it.
useAbstract add '0' byte at the start of the address to mark it as abstract socket address

◆ sendTo() [2/3]

bool SockUnix::sendTo ( const void *  msg,
size_t  len,
const std::string &  addrStr 
) const

Send the message using the socket to a specific address

Parameters
[in]msgpointer to message memory buffer
[in]lenmessage length
[in]addrStrUnix socket address (socket file)
Returns
true if message is sent
Note
true does NOT guarantee the frame was successfully arrives its target. Only the network layer sends it.
Remarks
keep for ABI backward compatibility.

◆ sendTo() [3/3]

bool SockUnix::sendTo ( const void *  msg,
size_t  len,
const std::string &  addrStr,
bool  useAbstract 
) const

Send the message using the socket to a specific address

Parameters
[in]msgpointer to message memory buffer
[in]lenmessage length
[in]addrStrUnix socket address (socket file)
[in]useAbstractuse Abstract socket address
Returns
true if message is sent
Note
true does NOT guarantee the frame was successfully arrives its target. Only the network layer sends it.
useAbstract add '0' byte at the start of the address to mark it as abstract socket address

◆ setDefSelfAddress()

bool SockUnix::setDefSelfAddress ( const std::string &  rootBase = "",
const std::string &  useDef = "" 
)

Set self address using predefined algorithm

Parameters
[in]rootBasebase used for root user
[in]useDefbase used for non root user
Returns
true if self address is updated
Note
address can not be changed after initializing. User can close the socket, change this value, and initialize a new socket.

◆ setPeerAddress() [1/2]

bool SockUnix::setPeerAddress ( const ConfigFile cfg,
const std::string &  section = "" 
)
inline

Set peer address using configuration file

Parameters
[in]cfgreference to configuration file object
[in]sectionin configuration file
Returns
true if peer address is updated
Note
calling without section will fetch value from "global" section

◆ setPeerAddress() [2/2]

bool SockUnix::setPeerAddress ( const std::string &  string,
bool  useAbstract = false 
)
inline

Set peer address

Parameters
[in]stringobject with peer address
[in]useAbstractuse Abstract socket address
Returns
true if peer address is updated
Note
useAbstract add '0' byte at the start of the address to mark it as abstract socket address

◆ setSelfAddress() [1/2]

bool SockUnix::setSelfAddress ( const std::string &  string)

Set self address

Parameters
[in]stringobject with self address
Returns
true if self address is updated
Note
address can not be changed after initializing. User can close the socket, change this value, and initialize a new socket.
Remarks
keep for ABI backward compatibility.

◆ setSelfAddress() [2/2]

bool SockUnix::setSelfAddress ( const std::string &  string,
bool  useAbstract 
)

Set self address

Parameters
[in]stringobject with self address
[in]useAbstractuse Abstract socket address
Returns
true if self address is updated
Note
address can not be changed after initializing. User can close the socket, change this value, and initialize a new socket.
useAbstract add '0' byte at the start of the address to mark it as abstract socket address

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