57 dgram_client_socket::dgram_client_socket(
void) : connected(false) {}
73 ssize_t dgram_client_socket::rcv(
void* buf,
size_t len,
int flags) {
78 if (-1 == (bytes = recv(sfd, buf, len, flags)))
80 "dgram_client_socket::rcv() - recv() failed!");
98 char* buffer =
new char[dest.size()];
100 memset(buffer, 0, dest.size());
102 if (-1 == (read_bytes = read(sock.
sfd, buffer, dest.size()))) {
104 if (sock.is_nonblocking && errno == EWOULDBLOCK) {
109 ">>(dgram_client_socket, std::string) " 110 "input: Error while reading!");
113 if (read_bytes < static_cast<ssize_t>(dest.size()))
114 dest.resize(read_bytes);
118 dest.assign(buffer, read_bytes);
135 ssize_t dgram_client_socket::snd(
const void* buf,
size_t len,
int flags) {
138 if (connected !=
true)
141 "dgram_client_socket::snd() - Socket is not connected!",
false);
143 if (-1 == (bytes = send(sfd, buf, len, flags)))
145 "dgram_client_socket::snd() - send() failed!");
159 "dgram_client_socket <<(const char*) output: Null buffer given!");
162 "dgram_client_socket <<(const char*) output: " 163 "DGRAM socket not connected!");
165 size_t len = strlen(str);
167 if (-1 == write(sock.
sfd, str, len))
170 "dgram_client_socket <<(const char*) output: Write failed!");
183 "dgram_client_socket <<(std::string) output: " 184 "DGRAM socket not connected!");
185 if (-1 == write(sock.
sfd, str.c_str(), str.size()))
188 "dgram_client_socket <<(std::string) output: Write failed!");
198 bool dgram_client_socket::getconn(
void)
const {
return is_connected(); }
203 bool dgram_client_socket::is_connected(
void)
const {
return connected; }
Contains libsocket elements.
Represents a generic "client" datagram socket, i.e. a datagram socket which can be connected.
This class is instantiated and thrown when an error occurs. If there's an error somewhere in libsocke...
dgram_client_socket & operator>>(dgram_client_socket &sock, string &dest)
Receive data from connected datagram socket.
dgram_client_socket & operator<<(dgram_client_socket &sock, const string &str)
Send data to connected peer.
int sfd
sfd is the sockets API file descriptor