@@ -51,7 +51,7 @@ class UdpServerImpl : public UdpServer {
5151 }
5252
5353 void broadcast (XmlCharBuffer && data, std::function<void (asio::error_code)> continuation) override {
54- write (std::move (data), &UdpServerImpl::m_multicastSendSocket, m_multicastDest, continuation);
54+ write (std::move (data), &UdpServerImpl::m_multicastSendSocket, m_multicastDest, false , continuation);
5555 }
5656
5757private:
@@ -157,13 +157,13 @@ class UdpServerImpl : public UdpServer {
157157 }
158158
159159 if (maybeReply)
160- write (std::move (*maybeReply), &UdpServerImpl::m_unicastSendSocket, m_recvSender);
160+ write (std::move (*maybeReply), &UdpServerImpl::m_unicastSendSocket, m_recvSender, true );
161161 read ();
162162 });
163163 }
164164
165165 void write (XmlCharBuffer && data, ip::udp::socket UdpServerImpl::*socketPtr, ip::udp::endpoint dest,
166- std::function<void (asio::error_code)> continuation = nullptr) {
166+ bool isUnicast, std::function<void (asio::error_code)> continuation = nullptr) {
167167 int repeatCount = (socketPtr == &UdpServerImpl::m_multicastSendSocket ? 4 : 2 );
168168 RefCountedContainerBuffer buffer (std::move (data));
169169 auto & socket = this ->*socketPtr;
@@ -173,14 +173,25 @@ class UdpServerImpl : public UdpServer {
173173 RefCountedContainerBuffer<XmlCharBuffer> buffer;
174174 ip::udp::socket & socket;
175175 ip::udp::endpoint dest;
176+ bool isUnicast;
176177 int repeatCount;
177178 std::function<void (asio::error_code)> continuation;
178179
179- void operator ()(const asio::error_code & ec, size_t /* bytesSent, ip::udp::socket * socket*/ ) {
180+ void operator ()(asio::error_code ec, size_t /* bytesSent, ip::udp::socket * socket*/ ) {
180181
181182 if (!me->m_handler )
182183 return ;
183184
185+ #ifdef __OpenBSD__
186+ // On OpenBSD unicast send_to can fail with EACCESS when firewall
187+ // blocks it. This isn't fatal and shouldn't be an error at all, so let's
188+ // log it and treat it as success
189+ if (isUnicast && ec == asio::error::access_denied) {
190+ WSDLOG_DEBUG (" UDP server on {}, error writing: blocked by firewall" , me->m_iface );
191+ ec = asio::error_code{};
192+ }
193+ #endif
194+
184195 if (ec) {
185196 if (ec != asio::error::operation_aborted) {
186197 WSDLOG_ERROR (" UDP server on {}, error writing: {}" , me->m_iface , ec.message ());
@@ -219,7 +230,7 @@ class UdpServerImpl : public UdpServer {
219230 else
220231 WSDLOG_DEBUG (" UDP on {}, sending {} bytes to {}" , m_iface, buffer.begin ()->size (), dest.address ().to_string ());
221232
222- socket.async_send_to (buffer, dest, Callback{refcnt_retain (this ), buffer, socket, dest, repeatCount, continuation});
233+ socket.async_send_to (buffer, dest, Callback{refcnt_retain (this ), buffer, socket, dest, isUnicast, repeatCount, continuation});
223234 }
224235
225236private:
0 commit comments