lib45d
45Drives C++ Library API Documentation
|
23 #include <45d/socket/Exceptions.hpp>
29 #include <sys/socket.h>
46 #ifndef FFD_SOCKET_BUFF_SZ
70 int res = socket(domain, type, protocol);
110 int res = send(fd, (
void *)str.c_str(), str.length(), flags);
137 void send_data(
const std::string &str,
int flags = 0,
int fd = 0) {
147 void send_data_async(
const std::vector<std::string> &vec,
int flags = 0,
int fd = 0) {
149 std::vector<std::string>::const_iterator itr = vec.begin();
152 for (; itr != vec.end(); ++itr) {
164 void send_data_sync(
const std::vector<std::string> &vec,
int flags = 0,
int fd = 0) {
176 void send_data(
const std::vector<std::string> &vec,
int flags = 0,
int fd = 0) {
191 memset(&buff, 0,
sizeof(buff));
194 bytes_read = recv(fd, &buff,
sizeof(buff) - 1, flags);
195 if (bytes_read == -1) {
199 buff[bytes_read] =
'\0';
201 }
while (bytes_read > 0
202 && recv(fd, &buff,
sizeof(buff) - 1, MSG_PEEK | MSG_DONTWAIT) > 0);
235 std::string payload, record;
237 std::stringstream ss(payload);
239 vec.push_back(record);
261 void receive_data(std::vector<std::string> &vec,
int flags = 0,
int fd = 0) {
281 void get_ack(
int fd) {
285 recv(fd, &ack_check, 1, 0);
286 if (ack_check !=
ACK) {
290 void send_ack(
int fd) {
293 send(fd, &
ACK, 1, 0);
int io_fd_
Connection fd.
Definition: SocketBase.hpp:278
Thrown when shutdown() fails.
Definition: Exceptions.hpp:116
void close_connection(int fd=0)
Close a connection.
Definition: SocketBase.hpp:90
void shutdown(int how=SHUT_RDWR)
Call shutdown() on the socket fd, waking any blocked threads.
Definition: SocketBase.hpp:269
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&,...
Definition: SocketBase.hpp:223
Thrown when read() fails.
Definition: Exceptions.hpp:107
const int _buff_sz
Size of recv buffer. Can be overridden by defining FFD_SOCKET_BUFF_SZ before including header.
Definition: SocketBase.hpp:45
Thrown when close(fd_) returns -1 with strerror(errno) as what.
Definition: Exceptions.hpp:48
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::Soc...
Definition: SocketBase.hpp:261
const int _backlog_default
Number of connections to queue.
Definition: SocketBase.hpp:39
45Drives namespace
Definition: Bytes.hpp:27
void receive_data_async(std::string &payload, int flags=0, int fd=0)
Receive a string.
Definition: SocketBase.hpp:186
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::SocketBa...
Definition: SocketBase.hpp:176
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.
Definition: SocketBase.hpp:164
char ACK
char to send for acknowledging reception
Definition: SocketBase.hpp:279
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&,...
Definition: SocketBase.hpp:137
Thrown when write() fails.
Definition: Exceptions.hpp:98
void send_data_async(const std::string &str, int flags=0, int fd=0)
Send a string.
Definition: SocketBase.hpp:107
Thrown when socket() returns -1 with strerror(errno) as what.
Definition: Exceptions.hpp:39
void send_data_sync(const std::string &str, int flags=0, int fd=0)
Send a string and wait for ACK.
Definition: SocketBase.hpp:123
Base Unix Socket Class for opening and closing the socket.
Definition: SocketBase.hpp:57
~SocketBase()
Destroy the Socket Base object. Calls close() on the socket fd.
Definition: SocketBase.hpp:82
const char _rec_delim
Record separator character.
Definition: SocketBase.hpp:51
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.
Definition: SocketBase.hpp:233
int fd_
File descriptor of socket.
Definition: SocketBase.hpp:277
SocketBase(int domain, int type, int protocol=0)
Construct a new Socket Base object. Opens a socket fd.
Definition: SocketBase.hpp:69
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.
Definition: SocketBase.hpp:249
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.
Definition: SocketBase.hpp:147
void receive_data_sync(std::string &payload, int flags=0, int fd=0)
Receive a string and reply with ACK.
Definition: SocketBase.hpp:211