Skip to content

iox::posix::UnixDomainSocket🔗

Wrapper class for unix domain socket.

#include <unix_domain_socket.hpp>

Inherits from DesignPattern::Creation< UnixDomainSocket, IpcChannelError >

Public Classes🔗

Name
struct NoPathPrefix_t

Public Types🔗

Name
using cxx::string< LONGEST_VALID_NAME > UdsName_t

Public Functions🔗

Name
UnixDomainSocket()
default constructor. The result is an invalid UnixDomainSocket object which can be reassigned later by using the move constructor.
UnixDomainSocket(const UnixDomainSocket & other)
UnixDomainSocket(UnixDomainSocket && other)
UnixDomainSocket & operator=(const UnixDomainSocket & other)
UnixDomainSocket & operator=(UnixDomainSocket && other)
~UnixDomainSocket()
cxx::expected< IpcChannelError > destroy()
close the unix domain socket.
cxx::expected< IpcChannelError > send(const std::string & msg) const
send a message using std::string.
cxx::expected< IpcChannelError > timedSend(const std::string & msg, const units::Duration & timeout) const
try to send a message for a given timeout duration using std::string
cxx::expected< std::string, IpcChannelError > receive() const
receive message using std::string.
cxx::expected< std::string, IpcChannelError > timedReceive(const units::Duration & timeout) const
try to receive message for a given timeout duration using std::string.
cxx::expected< bool, IpcChannelError > isOutdated()
checks whether the unix domain socket is outdated
cxx::expected< bool, IpcChannelError > unlinkIfExists(const UdsName_t & name)
unlink the provided unix domain socket
cxx::expected< bool, IpcChannelError > unlinkIfExists(const NoPathPrefix_t, const UdsName_t & name)
unlink the provided unix domain socket

Public Attributes🔗

Name
constexpr NoPathPrefix_t NoPathPrefix
constexpr char PATH_PREFIX
constexpr size_t MAX_MESSAGE_SIZE
Max message size is on linux = 4096 and on mac os = 2048. To have the same behavior on every platform we use 2048.
constexpr size_t SHORTEST_VALID_NAME
constexpr size_t NULL_TERMINATOR_SIZE
constexpr size_t LONGEST_VALID_NAME
The name length is limited by the size of the sockaddr_un::sun_path buffer and the path prefix.
constexpr int32_t ERROR_CODE
constexpr int32_t INVALID_FD

Friends🔗

Name
class DesignPattern::Creation< UnixDomainSocket, IpcChannelError >
for calling private constructor in create method

Additional inherited members🔗

Public Types inherited from DesignPattern::Creation< UnixDomainSocket, IpcChannelError >

Name
using Creation< DerivedClass, ErrorType > CreationPattern_t
using iox::cxx::expected< DerivedClass, ErrorType > result_t
using ErrorType errorType_t

Public Functions inherited from DesignPattern::Creation< UnixDomainSocket, IpcChannelError >

Name
template \<typename... Targs>
result_t
create(Targs &&... args)
factory method which guarantees that either a working object is produced or an error value describing the error during construction
result_t verify(DerivedClass && newObject)
verifies if a class was created successfully
template \<typename... Targs>
iox::cxx::expected< ErrorType >
placementCreate(void *const memory, Targs &&... args)
factory method which guarantees that either a working object is produced or an error value describing the error during construction
Creation() =default
Creation(Creation && rhs)
Creation(const Creation & rhs) =default
bool isInitialized() const
returns true if the object was constructed successfully, otherwise false

Protected Attributes inherited from DesignPattern::Creation< UnixDomainSocket, IpcChannelError >

Name
bool m_isInitialized
ErrorType m_errorValue

Public Types Documentation🔗

using UdsName_t🔗

using iox::posix::UnixDomainSocket::UdsName_t =  cxx::string<LONGEST_VALID_NAME>;

Public Functions Documentation🔗

function UnixDomainSocket🔗

UnixDomainSocket()

default constructor. The result is an invalid UnixDomainSocket object which can be reassigned later by using the move constructor.

function UnixDomainSocket🔗

UnixDomainSocket(
    const UnixDomainSocket & other
)

function UnixDomainSocket🔗

UnixDomainSocket(
    UnixDomainSocket && other
)

function operator=🔗

UnixDomainSocket & operator=(
    const UnixDomainSocket & other
)

function operator=🔗

UnixDomainSocket & operator=(
    UnixDomainSocket && other
)

function ~UnixDomainSocket🔗

~UnixDomainSocket()

function destroy🔗

cxx::expected< IpcChannelError > destroy()

close the unix domain socket.

function send🔗

cxx::expected< IpcChannelError > send(
    const std::string & msg
) const

send a message using std::string.

Parameters:

  • msg to send

Return: IpcChannelError if error occured

function timedSend🔗

cxx::expected< IpcChannelError > timedSend(
    const std::string & msg,
    const units::Duration & timeout
) const

try to send a message for a given timeout duration using std::string

Parameters:

  • msg to send
  • timout for the send operation

Return: IpcChannelError if error occured

function receive🔗

cxx::expected< std::string, IpcChannelError > receive() const

receive message using std::string.

Return: received message. In case of an error, IpcChannelError is returned and msg is empty.

function timedReceive🔗

cxx::expected< std::string, IpcChannelError > timedReceive(
    const units::Duration & timeout
) const

try to receive message for a given timeout duration using std::string.

Parameters:

  • timout for the receive operation

Return: received message. In case of an error, IpcChannelError is returned and msg is empty.

function isOutdated🔗

cxx::expected< bool, IpcChannelError > isOutdated()

checks whether the unix domain socket is outdated

Return: true if the unix domain socket is outdated, false otherwise, IpcChannelError if error occured

function unlinkIfExists🔗

static cxx::expected< bool, IpcChannelError > unlinkIfExists(
    const UdsName_t & name
)

unlink the provided unix domain socket

Parameters:

  • name of the unix domain socket to unlink

Return: true if the unix domain socket could be unlinked, false otherwise, IpcChannelError if error occured

function unlinkIfExists🔗

static cxx::expected< bool, IpcChannelError > unlinkIfExists(
    const NoPathPrefix_t,
    const UdsName_t & name
)

unlink the provided unix domain socket

Parameters:

  • NoPathPrefix signalling that this method does not add a path prefix
  • name of the unix domain socket to unlink

Return: true if the unix domain socket could be unlinked, false otherwise, IpcChannelError if error occured

Public Attributes Documentation🔗

variable NoPathPrefix🔗

static constexpr NoPathPrefix_t NoPathPrefix {};

variable PATH_PREFIX🔗

static constexpr char PATH_PREFIX = "/tmp/";

variable MAX_MESSAGE_SIZE🔗

static constexpr size_t MAX_MESSAGE_SIZE = 2048U;

Max message size is on linux = 4096 and on mac os = 2048. To have the same behavior on every platform we use 2048.

variable SHORTEST_VALID_NAME🔗

static constexpr size_t SHORTEST_VALID_NAME = 2U;

variable NULL_TERMINATOR_SIZE🔗

static constexpr size_t NULL_TERMINATOR_SIZE = 1;

variable LONGEST_VALID_NAME🔗

static constexpr size_t LONGEST_VALID_NAME = sizeof(sockaddr_un::sun_path) - 1;

The name length is limited by the size of the sockaddr_un::sun_path buffer and the path prefix.

variable ERROR_CODE🔗

static constexpr int32_t ERROR_CODE = -1;

variable INVALID_FD🔗

static constexpr int32_t INVALID_FD = -1;

Friends🔗

friend DesignPattern::Creation< UnixDomainSocket, IpcChannelError >🔗

friend class DesignPattern::Creation< UnixDomainSocket, IpcChannelError >;

for calling private constructor in create method


Updated on 31 May 2022 at 15:29:15 CEST