This class wraps all operations possible to do with a socket. More...
#include <socket.hpp>
Public Types | |
typedef std::unique_lock < std::recursive_mutex > | Guard |
Public Member Functions | |
Socket (int socketFD=-1) | |
Default constructor. More... | |
Socket (Socket &&socket) noexcept | |
~Socket () noexcept | |
Socket (const Socket &)=delete | |
Socket & | operator= (const Socket &)=delete |
Socket & | operator= (Socket &&)=delete |
int | getFD () const |
void | write (const void *bufferPtr, const size_t size) const |
Write data using the file descriptor. More... | |
void | read (void *bufferPtr, const size_t size) const |
Reads a value of the given type. More... | |
std::shared_ptr< Socket > | accept () |
Accepts connection. More... | |
Socket::Guard | getGuard () const |
Static Public Member Functions | |
static Socket | createSocket (const std::string &path) |
Prepares socket for accepting connections. More... | |
static Socket | connectSocket (const std::string &path, const int timeoutMs=1000) |
Connects to a socket. More... | |
Static Private Member Functions | |
static int | createSocketInternal (const std::string &path) |
static int | getSystemdSocketInternal (const std::string &path) |
Private Attributes | |
int | mFD |
std::recursive_mutex | mCommunicationMutex |
This class wraps all operations possible to do with a socket.
It has operations both for client and server application.
typedef std::unique_lock<std::recursive_mutex> cargo::ipc::Socket::Guard |
|
explicit |
Default constructor.
If socketFD is passed then it's passed by the Socket
socketFD | socket obtained outside the class. |
|
noexcept |
|
noexcept |
|
delete |
std::shared_ptr< Socket > cargo::ipc::Socket::accept | ( | ) |
Accepts connection.
Used by a server application. Blocking, called by a server.
|
static |
Connects to a socket.
Called as a client.
path | path to the socket |
|
static |
Prepares socket for accepting connections.
Called by a server.
path | path to the socket |
|
staticprivate |
int cargo::ipc::Socket::getFD | ( | ) | const |
Socket::Guard cargo::ipc::Socket::getGuard | ( | ) | const |
|
staticprivate |
void cargo::ipc::Socket::read | ( | void * | bufferPtr, |
const size_t | size | ||
) | const |
Reads a value of the given type.
bufferPtr | buffer with the data |
size | size of the buffer |
void cargo::ipc::Socket::write | ( | const void * | bufferPtr, |
const size_t | size | ||
) | const |
Write data using the file descriptor.
bufferPtr | buffer with the data |
size | size of the buffer |
|
mutableprivate |
|
private |