From 0c5c1549d011afadd49614a19980b1b2cdc66933 Mon Sep 17 00:00:00 2001 From: Andrej Babic Date: Fri, 15 May 2020 14:45:10 +0200 Subject: [PATCH] Move bind to end of socket --- core-buffer/src/UdpReceiver.cpp | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/core-buffer/src/UdpReceiver.cpp b/core-buffer/src/UdpReceiver.cpp index 392a9d6..1832674 100644 --- a/core-buffer/src/UdpReceiver.cpp +++ b/core-buffer/src/UdpReceiver.cpp @@ -35,15 +35,6 @@ void UdpReceiver::bind(const uint16_t port) server_address.sin_addr.s_addr = INADDR_ANY; server_address.sin_port = htons(port); - auto bind_result = ::bind( - socket_fd_, - reinterpret_cast(&server_address), - sizeof(server_address)); - - if (bind_result < 0) { - throw runtime_error("Cannot bind socket."); - } - timeval udp_socket_timeout; udp_socket_timeout.tv_sec = 0; udp_socket_timeout.tv_usec = BUFFER_UDP_US_TIMEOUT; @@ -60,6 +51,15 @@ void UdpReceiver::bind(const uint16_t port) "Cannot set SO_RCVBUF. " + string(strerror(errno))); }; //TODO: try to set SO_RCVLOWAT + + auto bind_result = ::bind( + socket_fd_, + reinterpret_cast(&server_address), + sizeof(server_address)); + + if (bind_result < 0) { + throw runtime_error("Cannot bind socket."); + } } int UdpReceiver::receive_many(mmsghdr* msgs, const size_t n_msgs)