Use 'send()' or 'sendto()' depending on whether or not the socket is

already connected to a remote address
This commit is contained in:
2025-07-18 11:11:21 -04:00
parent af242cb812
commit 2b911105a7

View File

@@ -55,7 +55,13 @@ void Sock::sendAll(std::string to_send) {
/* For UDP sockets */
if (this->protocol == ES_UDP) {
if (sendto(this->sock_fd, to_send.data(), str_length, 0, (struct sockaddr *)dest, addrlen) == -1) {
int retval;
if (this->has_remote_address()) {
retval = send(this->sock_fd, to_send.data(), str_length, 0);
} else {
retval = sendto(this->sock_fd, to_send.data(), str_length, 0, (struct sockaddr *)dest, addrlen);
}
if (retval == -1) {
throw errno;
}
}