diff --git a/include/libtorrent/broadcast_socket.hpp b/include/libtorrent/broadcast_socket.hpp index 134c973bb..c6280f8e2 100644 --- a/include/libtorrent/broadcast_socket.hpp +++ b/include/libtorrent/broadcast_socket.hpp @@ -85,6 +85,7 @@ namespace libtorrent { enum flags_t { flag_broadcast = 1 }; void send(char const* buffer, int size, error_code& ec, int flags = 0); + void send_to(char const* buffer, int size, udp::endpoint const& to, error_code& ec); void close(); int num_send_sockets() const { return int(m_unicast_sockets.size()); } diff --git a/src/broadcast_socket.cpp b/src/broadcast_socket.cpp index 067d4531d..dd65d6bd2 100644 --- a/src/broadcast_socket.cpp +++ b/src/broadcast_socket.cpp @@ -227,6 +227,28 @@ namespace libtorrent { ++m_outstanding_operations; } + void broadcast_socket::send_to(char const* buffer, int size + , udp::endpoint const& to, error_code& ec) + { + bool all_fail = true; + error_code e; + for (auto& s : m_sockets) + { + if (!s.socket) continue; + s.socket->send_to(boost::asio::buffer(buffer, std::size_t(size)), to, 0, e); + if (e) + { + s.socket->close(e); + s.socket.reset(); + } + else + { + all_fail = false; + } + } + if (all_fail) ec = e; + } + void broadcast_socket::send(char const* buffer, int const size , error_code& ec, int const flags) { diff --git a/test/test_upnp.cpp b/test/test_upnp.cpp index 56a506d42..206a7e1e2 100644 --- a/test/test_upnp.cpp +++ b/test/test_upnp.cpp @@ -87,7 +87,7 @@ void incoming_msearch(udp::endpoint const& from, span buffer) std::cout << "< incoming m-search from " << from << std::endl; - char msg[] = "HTTP/1.1 200 OK\r\n" + char const msg[] = "HTTP/1.1 200 OK\r\n" "ST:upnp:rootdevice\r\n" "USN:uuid:000f-66d6-7296000099dc::upnp:rootdevice\r\n" "Location: http://127.0.0.1:%d/upnp.xml\r\n" @@ -107,7 +107,9 @@ void incoming_msearch(udp::endpoint const& from, span buffer) #pragma clang diagnostic pop #endif error_code ec; - sock->send(buf, len, ec); + sock->send_to(buf, len, from, ec); + + std::cout << "> sending response to " << print_endpoint(from) << std::endl; if (ec) std::cout << "*** error sending " << ec.message() << std::endl; }