iceoryx_doc  1.0.1
Classes | Public Types | Public Member Functions | Static Public Member Functions | Static Public Attributes | Friends | List of all members
iox::posix::UnixDomainSocket Class Reference

Wrapper class for unix domain socket. More...

#include <unix_domain_socket.hpp>

Inheritance diagram for iox::posix::UnixDomainSocket:
Inheritance graph
[legend]
Collaboration diagram for iox::posix::UnixDomainSocket:
Collaboration graph
[legend]

Classes

struct  NoPathPrefix_t
 

Public Types

using UdsName_t = cxx::string< LONGEST_VALID_NAME >
 
- Public Types inherited from DesignPattern::Creation< UnixDomainSocket, IpcChannelError >
using CreationPattern_t = Creation< UnixDomainSocket, IpcChannelError >
 
using result_t = iox::cxx::expected< UnixDomainSocket, IpcChannelError >
 
using errorType_t = IpcChannelError
 

Public Member Functions

 UnixDomainSocket () noexcept
 default constructor. The result is an invalid UnixDomainSocket object which can be reassigned later by using the move constructor.
 
 UnixDomainSocket (const UnixDomainSocket &other)=delete
 
 UnixDomainSocket (UnixDomainSocket &&other) noexcept
 
UnixDomainSocketoperator= (const UnixDomainSocket &other)=delete
 
UnixDomainSocketoperator= (UnixDomainSocket &&other) noexcept
 
cxx::expected< IpcChannelError > destroy () noexcept
 close the unix domain socket.
 
cxx::expected< IpcChannelError > send (const std::string &msg) const noexcept
 send a message using std::string. More...
 
cxx::expected< IpcChannelError > timedSend (const std::string &msg, const units::Duration &timeout) const noexcept
 try to send a message for a given timeout duration using std::string More...
 
cxx::expected< std::string, IpcChannelError > receive () const noexcept
 receive message using std::string. More...
 
cxx::expected< std::string, IpcChannelError > timedReceive (const units::Duration &timeout) const noexcept
 try to receive message for a given timeout duration using std::string. More...
 
cxx::expected< bool, IpcChannelError > isOutdated () noexcept
 checks whether the unix domain socket is outdated More...
 
- Public Member Functions inherited from DesignPattern::Creation< UnixDomainSocket, IpcChannelError >
 Creation (Creation &&rhs) noexcept
 
 Creation (const Creation &rhs) noexcept=default
 
Creationoperator= (Creation &&rhs) noexcept
 
Creationoperator= (const Creation &rhs) noexcept=default
 
bool isInitialized () const noexcept
 returns true if the object was constructed successfully, otherwise false
 

Static Public Member Functions

static cxx::expected< bool, IpcChannelError > unlinkIfExists (const UdsName_t &name) noexcept
 unlink the provided unix domain socket More...
 
static cxx::expected< bool, IpcChannelError > unlinkIfExists (const NoPathPrefix_t, const UdsName_t &name) noexcept
 unlink the provided unix domain socket More...
 
- Static Public Member Functions inherited from DesignPattern::Creation< UnixDomainSocket, IpcChannelError >
static result_t create (Targs &&... args) noexcept
 factory method which guarantees that either a working object is produced or an error value describing the error during construction More...
 
static result_t verify (UnixDomainSocket &&newObject) noexcept
 verifies if a class was created successfully More...
 
static iox::cxx::expected< IpcChannelError > placementCreate (void *const memory, Targs &&... args) noexcept
 factory method which guarantees that either a working object is produced or an error value describing the error during construction More...
 

Static Public Attributes

static constexpr NoPathPrefix_t NoPathPrefix {}
 
static constexpr char PATH_PREFIX [] = "/tmp/"
 
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.
 
static constexpr size_t SHORTEST_VALID_NAME = 2U
 
static constexpr size_t NULL_TERMINATOR_SIZE = 1
 
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.
 
static constexpr int32_t ERROR_CODE = -1
 
static constexpr int32_t INVALID_FD = -1
 

Friends

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

Additional Inherited Members

- Protected Attributes inherited from DesignPattern::Creation< UnixDomainSocket, IpcChannelError >
bool m_isInitialized
 
IpcChannelError m_errorValue
 

Detailed Description

Wrapper class for unix domain socket.

Member Function Documentation

◆ isOutdated()

cxx::expected<bool, IpcChannelError> iox::posix::UnixDomainSocket::isOutdated ( )
noexcept

checks whether the unix domain socket is outdated

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

◆ receive()

cxx::expected<std::string, IpcChannelError> iox::posix::UnixDomainSocket::receive ( ) const
noexcept

receive message using std::string.

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

◆ send()

cxx::expected<IpcChannelError> iox::posix::UnixDomainSocket::send ( const std::string &  msg) const
noexcept

send a message using std::string.

Parameters
msgto send
Returns
IpcChannelError if error occured

◆ timedReceive()

cxx::expected<std::string, IpcChannelError> iox::posix::UnixDomainSocket::timedReceive ( const units::Duration timeout) const
noexcept

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

Parameters
timoutfor the receive operation
Returns
received message. In case of an error, IpcChannelError is returned and msg is empty.

◆ timedSend()

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

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

Parameters
msgto send
timoutfor the send operation
Returns
IpcChannelError if error occured

◆ unlinkIfExists() [1/2]

static cxx::expected<bool, IpcChannelError> iox::posix::UnixDomainSocket::unlinkIfExists ( const  NoPathPrefix_t,
const UdsName_t name 
)
staticnoexcept

unlink the provided unix domain socket

Parameters
NoPathPrefixsignalling that this method does not add a path prefix
nameof the unix domain socket to unlink
Returns
true if the unix domain socket could be unlinked, false otherwise, IpcChannelError if error occured

◆ unlinkIfExists() [2/2]

static cxx::expected<bool, IpcChannelError> iox::posix::UnixDomainSocket::unlinkIfExists ( const UdsName_t name)
staticnoexcept

unlink the provided unix domain socket

Parameters
nameof the unix domain socket to unlink
Returns
true if the unix domain socket could be unlinked, false otherwise, IpcChannelError if error occured

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