summaryrefslogtreecommitdiffstats
path: root/src/UDPClient
diff options
context:
space:
mode:
authorSuren A. Chilingaryan <csa@suren.me>2018-08-06 18:35:13 +0200
committerSuren A. Chilingaryan <csa@suren.me>2018-08-06 18:35:13 +0200
commit09b7e077f10fe324774f759086f3596947d69b19 (patch)
treed9d910844704459a5390382949d02648f3a3f5a9 /src/UDPClient
parent76affa8334acbd21f3a1186fdaace1efe93e2e31 (diff)
downloadods-09b7e077f10fe324774f759086f3596947d69b19.tar.gz
ods-09b7e077f10fe324774f759086f3596947d69b19.tar.bz2
ods-09b7e077f10fe324774f759086f3596947d69b19.tar.xz
ods-09b7e077f10fe324774f759086f3596947d69b19.zip
Send multiple packets in one system call
Diffstat (limited to 'src/UDPClient')
-rw-r--r--src/UDPClient/UDPClient.cpp13
-rw-r--r--src/UDPClient/UDPClient.h1
2 files changed, 14 insertions, 0 deletions
diff --git a/src/UDPClient/UDPClient.cpp b/src/UDPClient/UDPClient.cpp
index 1d427ba..b9d55d0 100644
--- a/src/UDPClient/UDPClient.cpp
+++ b/src/UDPClient/UDPClient.cpp
@@ -64,12 +64,21 @@
{
throw udp_client_server_runtime_error(("invalid address or port: \"" + addr + ":" + decimal_port + "\"").c_str());
}
+
f_socket = socket(f_addrinfo->ai_family, SOCK_DGRAM | SOCK_CLOEXEC, IPPROTO_UDP);
if(f_socket == -1)
{
freeaddrinfo(f_addrinfo);
throw udp_client_server_runtime_error(("could not create socket for: \"" + addr + ":" + decimal_port + "\"").c_str());
}
+
+ if (connect(f_socket, f_addrinfo->ai_addr, f_addrinfo->ai_addrlen))
+ {
+ close(f_socket);
+ freeaddrinfo(f_addrinfo);
+ throw udp_client_server_runtime_error(("could not connect socket for: \"" + addr + ":" + decimal_port + "\"").c_str());
+ }
+
printf("Created client %d\n", f_port);
}
@@ -140,3 +149,7 @@
int UDPClient::send(const char *msg, std::size_t size){
return sendto(f_socket, msg, size, 0, f_addrinfo->ai_addr, f_addrinfo->ai_addrlen);
}
+
+ int UDPClient::msend(int n, struct mmsghdr *msg){
+ return sendmmsg(f_socket, msg, n, 0);
+ }
diff --git a/src/UDPClient/UDPClient.h b/src/UDPClient/UDPClient.h
index f6cf0d6..f1c8a8d 100644
--- a/src/UDPClient/UDPClient.h
+++ b/src/UDPClient/UDPClient.h
@@ -33,6 +33,7 @@ public:
std::string get_addr() const;
int send(const char *msg, size_t size);
+ int msend(int n, struct mmsghdr *msg);
private:
int f_socket;