16 #ifndef IOX_UTILS_POSIX_WRAPPER_UNIX_DOMAIN_SOCKET_HPP
17 #define IOX_UTILS_POSIX_WRAPPER_UNIX_DOMAIN_SOCKET_HPP
19 #include "iceoryx_utils/cxx/optional.hpp"
20 #include "iceoryx_utils/design_pattern/creation.hpp"
21 #include "iceoryx_utils/internal/posix_wrapper/ipc_channel.hpp"
22 #include "iceoryx_utils/internal/units/duration.hpp"
23 #include "iceoryx_utils/platform/fcntl.hpp"
24 #include "iceoryx_utils/platform/mqueue.hpp"
25 #include "iceoryx_utils/platform/stat.hpp"
26 #include "iceoryx_utils/platform/un.hpp"
40 static constexpr
char PATH_PREFIX[] =
"/tmp/";
45 static constexpr
size_t SHORTEST_VALID_NAME = 2U;
46 static constexpr
size_t NULL_TERMINATOR_SIZE = 1;
49 static constexpr int32_t ERROR_CODE = -1;
50 static constexpr int32_t INVALID_FD = -1;
81 cxx::expected<IpcChannelError>
destroy() noexcept;
86 cxx::expected<IpcChannelError>
send(const std::
string& msg) const noexcept;
92 cxx::expected<IpcChannelError>
timedSend(const std::
string& msg, const units::Duration& timeout) const noexcept;
96 cxx::expected<std::
string, IpcChannelError>
receive() const noexcept;
101 cxx::expected<std::
string, IpcChannelError>
timedReceive(const units::Duration& timeout) const noexcept;
115 const IpcChannelMode mode,
116 const IpcChannelSide channelSide,
118 const uint64_t maxMsgNumber = 10U) noexcept;
129 const IpcChannelMode mode,
130 const IpcChannelSide channelSide,
132 const uint64_t maxMsgNumber = 10U) noexcept;
138 cxx::expected<IpcChannelError> initalizeSocket(const IpcChannelMode mode) noexcept;
142 IpcChannelError convertErrnoToIpcChannelError(const int32_t errnum) const noexcept;
144 static
bool isNameValid(const
UdsName_t& name) noexcept;
148 cxx::expected<IpcChannelError> closeFileDescriptor() noexcept;
152 IpcChannelSide m_channelSide;
153 int32_t m_sockfd{INVALID_FD};
154 struct sockaddr_un m_sockAddr;
This pattern can be used if you write an abstraction where you have to throw an exception in the cons...
Definition: creation.hpp:99
Wrapper class for unix domain socket.
Definition: unix_domain_socket.hpp:34
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
static 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.
Definition: unix_domain_socket.hpp:48
static cxx::expected< bool, IpcChannelError > unlinkIfExists(const UdsName_t &name) noexcept
unlink the provided unix domain socket
static 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...
Definition: unix_domain_socket.hpp:44
cxx::expected< bool, IpcChannelError > isOutdated() noexcept
checks whether the unix domain socket is outdated
cxx::expected< std::string, IpcChannelError > receive() const noexcept
receive message using std::string.
UnixDomainSocket() noexcept
default constructor. The result is an invalid UnixDomainSocket object which can be reassigned later b...
cxx::expected< IpcChannelError > send(const std::string &msg) const noexcept
send a message using std::string.
cxx::expected< std::string, IpcChannelError > timedReceive(const units::Duration &timeout) const noexcept
try to receive message for a given timeout duration using std::string.
cxx::expected< IpcChannelError > destroy() noexcept
close the unix domain socket.
building block to easily create free function for logging in a library context
Definition: lockfree_queue.hpp:28
Definition: unix_domain_socket.hpp:37