diff --git a/src/peer_connection.cpp b/src/peer_connection.cpp index 56950e994..c98d89c01 100644 --- a/src/peer_connection.cpp +++ b/src/peer_connection.cpp @@ -3636,7 +3636,22 @@ namespace libtorrent disconnect(ec.message().c_str()); return; } - m_socket->bind(t->get_interface(), ec); + + tcp::endpoint bind_interface = t->get_interface(); + + std::pair const& out_ports = m_ses.settings().outgoing_ports; + if (out_ports.first > 0 && out_ports.second >= out_ports.first) + { + m_socket->set_option(socket_acceptor::reuse_address(true), ec); + if (ec) + { + disconnect(ec.message().c_str()); + return; + } + bind_interface.port(m_ses.next_port()); + } + + m_socket->bind(bind_interface, ec); if (ec) { disconnect(ec.message().c_str()); diff --git a/src/torrent.cpp b/src/torrent.cpp index bbe805beb..2dad5b71e 100644 --- a/src/torrent.cpp +++ b/src/torrent.cpp @@ -2308,11 +2308,6 @@ namespace libtorrent s->get().set_no_connect(true); } - std::pair const& out_ports = m_settings.outgoing_ports; - error_code ec; - if (out_ports.first > 0 && out_ports.second >= out_ports.first) - s->bind(tcp::endpoint(address(), m_ses.next_port()), ec); - boost::intrusive_ptr c(new (std::nothrow) web_peer_connection( m_ses, shared_from_this(), s, a, url, 0)); if (!c) return; @@ -2891,10 +2886,6 @@ namespace libtorrent bool ret = instantiate_connection(m_ses.m_io_service, m_ses.peer_proxy(), *s); (void)ret; TORRENT_ASSERT(ret); - std::pair const& out_ports = m_ses.settings().outgoing_ports; - error_code ec; - if (out_ports.first > 0 && out_ports.second >= out_ports.first) - s->bind(tcp::endpoint(address(), m_ses.next_port()), ec); boost::intrusive_ptr c(new bt_peer_connection( m_ses, shared_from_this(), s, a, peerinfo)); @@ -2950,7 +2941,8 @@ namespace libtorrent return false; } #endif - return true; + + return peerinfo->connection; } bool torrent::set_metadata(char const* metadata_buf, int metadata_size)