Throw errno instead of errno * -1, if an error is encountered with sending or receiving

master
Aadhavan Srinivasan 7 months ago
parent 3bf65ab8f9
commit d842485103

@ -50,7 +50,9 @@ void Sock::sendAll(std::string to_send) {
/* For UDP sockets */
if (this->protocol == ES_UDP) {
sendto(this->sock_fd, to_send.data(), str_length, 0, (struct sockaddr *)dest, addrlen);
if (sendto(this->sock_fd, to_send.data(), str_length, 0, (struct sockaddr *)dest, addrlen) == -1) {
throw errno;
}
}
/* For TCP sockets */
else {
@ -58,7 +60,7 @@ void Sock::sendAll(std::string to_send) {
/* Send the data to the 'other_socket' variable, which should be set by the client and server methods */
num_bytes_sent = send(this->other_socket, to_send.substr(total_bytes_sent).c_str(), str_length - total_bytes_sent, 0);
if (num_bytes_sent < 0) {
throw errno * -1;
throw errno;
}
total_bytes_sent += num_bytes_sent;
}
@ -89,6 +91,9 @@ char* Sock::recvAll() {
if (num_bytes_received == 0) {
return NULL;
}
if (num_bytes_received < 0) {
throw errno;
}
/* Null-terminate the string */
*(buffer + num_bytes_received) = '\0';
return buffer;
@ -106,7 +111,7 @@ char* Sock::recvAll() {
}
if (num_bytes_received < 0) {
throw errno * -1;
throw errno;
}
total_bytes_received += num_bytes_received;
has_been_read = true;

Loading…
Cancel
Save