lib45d
45Drives C++ Library Development Documentation
Public Member Functions | Private Member Functions | Private Attributes | List of all members
ffd::UnixSocketServer Class Reference

Unix Socket Server class. Used for IPC through a named socket inode. More...

#include <45d/socket/UnixSocketServer.hpp>

Inheritance diagram for ffd::UnixSocketServer:
Inheritance graph
[legend]
Collaboration diagram for ffd::UnixSocketServer:
Collaboration graph
[legend]

Public Member Functions

 UnixSocketServer (const std::string &path, int backlog=Socket::_backlog_default)
 Construct a new Unix Socket Server object. More...
 
 ~UnixSocketServer ()
 Destroy the Unix Socket Server object. More...
 
int wait_for_connection ()
 Uses accept() to block and wait for a connection, returning a file descriptor to the connection. Also sets internal io_fd_ for later use. More...
 
- Public Member Functions inherited from ffd::SocketBase
 SocketBase (int domain, int type, int protocol=0)
 Construct a new Socket Base object. Opens a socket fd. More...
 
 ~SocketBase ()
 Destroy the Socket Base object. Calls close() on the socket fd. More...
 
void close_connection (int fd=0)
 Close a connection. More...
 
void send_data_async (const std::string &str, int flags=0, int fd=0)
 Send a string. More...
 
void send_data_sync (const std::string &str, int flags=0, int fd=0)
 Send a string and wait for ACK. More...
 
void send_data (const std::string &str, int flags=0, int fd=0)
 Send a string and wait for ACK (alias for ffd::SocketBase::send_data_sync(const std::string&, int, int)) More...
 
void send_data_async (const std::vector< std::string > &vec, int flags=0, int fd=0)
 Send a vector as a record separator (0x1E) delimited string. More...
 
void send_data_sync (const std::vector< std::string > &vec, int flags=0, int fd=0)
 Send a vector as a record separator (0x1E) delimited string and wait for ACK. More...
 
void send_data (const std::vector< std::string > &vec, int flags=0, int fd=0)
 Send a vector as a record separator (0x1E) delimited string and wait for ACK (alias for ffd::SocketBase::send_data_sync(const std::vector<std::string>&, int, int)) More...
 
void receive_data_async (std::string &payload, int flags=0, int fd=0)
 Receive a string. More...
 
void receive_data_sync (std::string &payload, int flags=0, int fd=0)
 Receive a string and reply with ACK. More...
 
void receive_data (std::string &payload, int flags=0, int fd=0)
 Receive a string and reply with ACK (alias for ffd::SocketBase::receive_data_sync(std::string&, int, int)) More...
 
void receive_data_async (std::vector< std::string > &vec, int flags=0, int fd=0)
 Receive a vector as a record separator (0x1E) delimited string. More...
 
void receive_data_sync (std::vector< std::string > &vec, int flags=0, int fd=0)
 Receive a vector as a record separator (0x1E) delimited string and reply with ACK. More...
 
void receive_data (std::vector< std::string > &vec, int flags=0, int fd=0)
 Receive a vector as a record separator (0x1E) delimited string and reply with ACK (alias for ffd::SocketBase::receive_data_sync(std::vector<std::string>&, int, int)) More...
 
void shutdown (int how=SHUT_RDWR)
 Call shutdown() on the socket fd, waking any blocked threads. More...
 

Private Member Functions

void bind (void)
 Set up socket address structs and bind to the address inode path. More...
 
void listen (int backlog)
 Start listening for connections. More...
 

Private Attributes

const int domain_
 Socket domain, always AF_UNIX.
 
const std::string socket_path_
 Path to socket inode, equal to address.
 
struct sockaddr_un sock_addr_
 Unix socket address structs.
 
std::vector< int > connections_
 vector of open connections for closing in dtor
 

Additional Inherited Members

- Protected Attributes inherited from ffd::SocketBase
int fd_
 File descriptor of socket.
 
int io_fd_
 Connection fd.
 
char ACK
 char to send for acknowledging reception
 

Detailed Description

Unix Socket Server class. Used for IPC through a named socket inode.

Constructor & Destructor Documentation

◆ UnixSocketServer()

ffd::UnixSocketServer::UnixSocketServer ( const std::string &  path,
int  backlog = Socket::_backlog_default 
)
inline

Construct a new Unix Socket Server object.

Parameters
pathPath to socket inode
backlogNumber of connections to queue

◆ ~UnixSocketServer()

ffd::UnixSocketServer::~UnixSocketServer ( )
inline

Destroy the Unix Socket Server object.

Closes all connections and unlinks the socket inode

Member Function Documentation

◆ bind()

void ffd::UnixSocketServer::bind ( void  )
inlineprivate

Set up socket address structs and bind to the address inode path.

◆ listen()

void ffd::UnixSocketServer::listen ( int  backlog)
inlineprivate

Start listening for connections.

Parameters
backlog

◆ wait_for_connection()

int ffd::UnixSocketServer::wait_for_connection ( )
inline

Uses accept() to block and wait for a connection, returning a file descriptor to the connection. Also sets internal io_fd_ for later use.

Returns
int fd of connection

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