diff options
author | Suren A. Chilingaryan <csa@suren.me> | 2018-07-25 15:57:55 +0200 |
---|---|---|
committer | Suren A. Chilingaryan <csa@suren.me> | 2018-07-25 15:57:55 +0200 |
commit | 76affa8334acbd21f3a1186fdaace1efe93e2e31 (patch) | |
tree | 32065ef3866c4759f00f86e91cc01a6e24134269 /src/UDPServer | |
parent | 41d41b7deb416167da5a0de2638ecea078c13ea6 (diff) | |
download | ods-76affa8334acbd21f3a1186fdaace1efe93e2e31.tar.gz ods-76affa8334acbd21f3a1186fdaace1efe93e2e31.tar.bz2 ods-76affa8334acbd21f3a1186fdaace1efe93e2e31.tar.xz ods-76affa8334acbd21f3a1186fdaace1efe93e2e31.zip |
Recieve multiple packets in one system call
Diffstat (limited to 'src/UDPServer')
-rw-r--r-- | src/UDPServer/UDPServer.cpp | 16 | ||||
-rw-r--r-- | src/UDPServer/UDPServer.h | 1 |
2 files changed, 17 insertions, 0 deletions
diff --git a/src/UDPServer/UDPServer.cpp b/src/UDPServer/UDPServer.cpp index 8c9decf..42166b4 100644 --- a/src/UDPServer/UDPServer.cpp +++ b/src/UDPServer/UDPServer.cpp @@ -81,6 +81,13 @@ UDPServer::UDPServer(const std::string& addr, int port) close(f_socket); throw udp_client_server_runtime_error(("could not bind UDP socket with: \"" + addr + ":" + decimal_port + "\"").c_str()); } + +/* + int a = 134217728; + if (setsockopt(f_socket, SOL_SOCKET, SO_RCVBUF, &a, sizeof(int)) == -1) { + fprintf(stderr, "Error setting socket opts: %s\n", strerror(errno)); + } +*/ } /** \brief Clean up the UDP server. @@ -184,3 +191,12 @@ int UDPServer::timed_recv(char *msg, size_t max_size, int max_wait_s) // our socket has data return ::recv(f_socket, msg, max_size, 0); } + +int UDPServer::mrecv(int n, struct mmsghdr *msg, int max_wait_s) +{ + struct timespec timeout; + timeout.tv_sec = max_wait_s; + timeout.tv_nsec = 0; + + return recvmmsg(f_socket, msg, n, MSG_WAITFORONE, &timeout); +} diff --git a/src/UDPServer/UDPServer.h b/src/UDPServer/UDPServer.h index 22f33b3..ed0e033 100644 --- a/src/UDPServer/UDPServer.h +++ b/src/UDPServer/UDPServer.h @@ -34,6 +34,7 @@ public: int recv(char *msg, size_t max_size); int timed_recv(char *msg, size_t max_size, int max_wait_ms); + int mrecv(int n, struct mmsghdr *msg, int max_wait_s); private: int f_socket; |