improve test_upnp by responding with a unicast message
This commit is contained in:
parent
2a15b25ab3
commit
659a78eb56
|
@ -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()); }
|
||||
|
|
|
@ -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)
|
||||
{
|
||||
|
|
|
@ -87,7 +87,7 @@ void incoming_msearch(udp::endpoint const& from, span<char const> 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<char const> 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;
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue