Fork Vasum on GitHub Official Vasum Wiki on Tizen.org
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
cargo::ipc::Socket Class Reference

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
 
Socketoperator= (const Socket &)=delete
 
Socketoperator= (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< Socketaccept ()
 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
 

Detailed Description

This class wraps all operations possible to do with a socket.

It has operations both for client and server application.

Member Typedef Documentation

typedef std::unique_lock<std::recursive_mutex> cargo::ipc::Socket::Guard

Constructor & Destructor Documentation

cargo::ipc::Socket::Socket ( int  socketFD = -1)
explicit

Default constructor.

If socketFD is passed then it's passed by the Socket

Parameters
socketFDsocket obtained outside the class.
cargo::ipc::Socket::Socket ( Socket &&  socket)
noexcept
cargo::ipc::Socket::~Socket ( )
noexcept
cargo::ipc::Socket::Socket ( const Socket )
delete

Member Function Documentation

std::shared_ptr< Socket > cargo::ipc::Socket::accept ( )

Accepts connection.

Used by a server application. Blocking, called by a server.

Socket cargo::ipc::Socket::connectSocket ( const std::string &  path,
const int  timeoutMs = 1000 
)
static

Connects to a socket.

Called as a client.

Parameters
pathpath to the socket
Returns
connected socket
Socket cargo::ipc::Socket::createSocket ( const std::string &  path)
static

Prepares socket for accepting connections.

Called by a server.

Parameters
pathpath to the socket
Returns
created socket
int cargo::ipc::Socket::createSocketInternal ( const std::string &  path)
staticprivate
int cargo::ipc::Socket::getFD ( ) const
Returns
reference to the socket's file descriptor
Socket::Guard cargo::ipc::Socket::getGuard ( ) const
static int cargo::ipc::Socket::getSystemdSocketInternal ( const std::string &  path)
staticprivate
Socket& cargo::ipc::Socket::operator= ( const Socket )
delete
Socket& cargo::ipc::Socket::operator= ( Socket &&  )
delete
void cargo::ipc::Socket::read ( void *  bufferPtr,
const size_t  size 
) const

Reads a value of the given type.

Parameters
bufferPtrbuffer with the data
sizesize of the buffer
void cargo::ipc::Socket::write ( const void *  bufferPtr,
const size_t  size 
) const

Write data using the file descriptor.

Parameters
bufferPtrbuffer with the data
sizesize of the buffer

Member Data Documentation

std::recursive_mutex cargo::ipc::Socket::mCommunicationMutex
mutableprivate
int cargo::ipc::Socket::mFD
private

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