broadcast socket fix

This commit is contained in:
Arvid Norberg 2008-01-03 10:58:16 +00:00
parent 5b2f1d70e8
commit 29ccb9220b
2 changed files with 8 additions and 1 deletions

View File

@ -71,6 +71,7 @@ namespace libtorrent
udp::endpoint remote;
void close()
{
if (!socket) return;
asio::error_code ec;
socket->close(ec);
}

View File

@ -187,12 +187,17 @@ namespace libtorrent
for (std::list<socket_entry>::iterator i = m_unicast_sockets.begin()
, end(m_unicast_sockets.end()); i != end; ++i)
{
if (!i->socket) continue;
asio::error_code e;
i->socket->send_to(asio::buffer(buffer, size), m_multicast_endpoint, 0, e);
#ifndef NDEBUG
// std::cerr << " sending on " << i->socket->local_endpoint().address().to_string() << std::endl;
#endif
if (e) ec = e;
if (e)
{
i->socket->close(e);
i->socket.reset();
}
}
}
@ -201,6 +206,7 @@ namespace libtorrent
{
if (ec || bytes_transferred == 0 || !m_on_receive) return;
m_on_receive(s->remote, s->buffer, bytes_transferred);
if (!s->socket) return;
s->socket->async_receive_from(asio::buffer(s->buffer, sizeof(s->buffer))
, s->remote, bind(&broadcast_socket::on_receive, this, s, _1, _2));
}