From 2b911105a709a77f8fb80d48ad93e8883e3db704 Mon Sep 17 00:00:00 2001 From: Aadhavan Srinivasan Date: Fri, 18 Jul 2025 11:11:21 -0400 Subject: [PATCH] Use 'send()' or 'sendto()' depending on whether or not the socket is already connected to a remote address --- sock.cpp | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/sock.cpp b/sock.cpp index 9baf171..f6daec8 100644 --- a/sock.cpp +++ b/sock.cpp @@ -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; } }