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

Base Unix Socket Class for opening and closing the socket. More...

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

Inheritance diagram for ffd::SocketBase:
Inheritance graph
[legend]

Public Member Functions

 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...
 

Protected Attributes

int fd_
 File descriptor of socket.
 
int io_fd_
 Connection fd.
 
char ACK
 char to send for acknowledging reception
 

Private Member Functions

void get_ack (int fd)
 
void send_ack (int fd)
 

Detailed Description

Base Unix Socket Class for opening and closing the socket.

Constructor & Destructor Documentation

◆ SocketBase()

ffd::SocketBase::SocketBase ( int  domain,
int  type,
int  protocol = 0 
)
inline

Construct a new Socket Base object. Opens a socket fd.

see man socket(2) for details

Parameters
domainUsually AF_UNIX or AF_INET
typeUsually SOCK_STREAM
protocolNormally just 0

◆ ~SocketBase()

ffd::SocketBase::~SocketBase ( )
inline

Destroy the Socket Base object. Calls close() on the socket fd.

Member Function Documentation

◆ close_connection()

void ffd::SocketBase::close_connection ( int  fd = 0)
inline

Close a connection.

Parameters
fdSocket connection fd or default for internal io_fd_

◆ receive_data() [1/2]

void ffd::SocketBase::receive_data ( std::string &  payload,
int  flags = 0,
int  fd = 0 
)
inline

Receive a string and reply with ACK (alias for ffd::SocketBase::receive_data_sync(std::string&, int, int))

Parameters
payloadReceived message returned by reference
flagssee man send(2)
fdOptional file descriptor for connection

◆ receive_data() [2/2]

void ffd::SocketBase::receive_data ( std::vector< std::string > &  vec,
int  flags = 0,
int  fd = 0 
)
inline

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))

Parameters
vecReceived vector returned by reference
flagssee man send(2)
fdOptional file descriptor for connection

◆ receive_data_async() [1/2]

void ffd::SocketBase::receive_data_async ( std::string &  payload,
int  flags = 0,
int  fd = 0 
)
inline

Receive a string.

Parameters
payloadReceived message returned by reference
flagssee man send(2)
fdOptional file descriptor for connection

◆ receive_data_async() [2/2]

void ffd::SocketBase::receive_data_async ( std::vector< std::string > &  vec,
int  flags = 0,
int  fd = 0 
)
inline

Receive a vector as a record separator (0x1E) delimited string.

Parameters
vecReceived vector returned by reference
flagssee man send(2)
fdOptional file descriptor for connection

◆ receive_data_sync() [1/2]

void ffd::SocketBase::receive_data_sync ( std::string &  payload,
int  flags = 0,
int  fd = 0 
)
inline

Receive a string and reply with ACK.

Parameters
payloadReceived message returned by reference
flagssee man send(2)
fdOptional file descriptor for connection

◆ receive_data_sync() [2/2]

void ffd::SocketBase::receive_data_sync ( std::vector< std::string > &  vec,
int  flags = 0,
int  fd = 0 
)
inline

Receive a vector as a record separator (0x1E) delimited string and reply with ACK.

Parameters
vecReceived vector returned by reference
flagssee man send(2)
fdOptional file descriptor for connection

◆ send_data() [1/2]

void ffd::SocketBase::send_data ( const std::string &  str,
int  flags = 0,
int  fd = 0 
)
inline

Send a string and wait for ACK (alias for ffd::SocketBase::send_data_sync(const std::string&, int, int))

Parameters
strMessage to send
flagssee man send(2)
fdOptional file descriptor for connection

◆ send_data() [2/2]

void ffd::SocketBase::send_data ( const std::vector< std::string > &  vec,
int  flags = 0,
int  fd = 0 
)
inline

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))

Parameters
vecVector to send
flagssee man send(2)
fdOptional file descriptor for connection

◆ send_data_async() [1/2]

void ffd::SocketBase::send_data_async ( const std::string &  str,
int  flags = 0,
int  fd = 0 
)
inline

Send a string.

Parameters
strMessage to send
flagssee man send(2)
fdOptional file descriptor for connection

◆ send_data_async() [2/2]

void ffd::SocketBase::send_data_async ( const std::vector< std::string > &  vec,
int  flags = 0,
int  fd = 0 
)
inline

Send a vector as a record separator (0x1E) delimited string.

Parameters
vecVector to send
flagssee man send(2)
fdOptional file descriptor for connection

◆ send_data_sync() [1/2]

void ffd::SocketBase::send_data_sync ( const std::string &  str,
int  flags = 0,
int  fd = 0 
)
inline

Send a string and wait for ACK.

Parameters
strMessage to send
flagssee man send(2)
fdOptional file descriptor for connection

◆ send_data_sync() [2/2]

void ffd::SocketBase::send_data_sync ( const std::vector< std::string > &  vec,
int  flags = 0,
int  fd = 0 
)
inline

Send a vector as a record separator (0x1E) delimited string and wait for ACK.

Parameters
vecVector to send
flagssee man send(2)
fdOptional file descriptor for connection

◆ shutdown()

void ffd::SocketBase::shutdown ( int  how = SHUT_RDWR)
inline

Call shutdown() on the socket fd, waking any blocked threads.

Parameters
howEither SHUT_RD, SHUT_WR, or SHUT_RDWR

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