From b3aeb7bb277dfb9362ff9a95447faa0f3b3c0419 Mon Sep 17 00:00:00 2001 From: subtly Date: Sun, 10 May 2015 10:12:14 +0200 Subject: [PATCH 1/2] Prevent socket from closing due to attempt to send to bad address. --- libp2p/UDP.h | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/libp2p/UDP.h b/libp2p/UDP.h index 97136ee43..4cab9b22d 100644 --- a/libp2p/UDP.h +++ b/libp2p/UDP.h @@ -223,10 +223,15 @@ void UDPSocket::doWrite() const UDPDatagram& datagram = m_sendQ[0]; auto self(UDPSocket::shared_from_this()); - m_socket.async_send_to(boost::asio::buffer(datagram.data), datagram.endpoint(), [this, self](boost::system::error_code _ec, std::size_t) + bi::udp::endpoint endpoint(datagram.endpoint()); + m_socket.async_send_to(boost::asio::buffer(datagram.data), endpoint, [this, self, endpoint](boost::system::error_code _ec, std::size_t) { - if (_ec || m_closed) + if (m_closed) return disconnectWithError(_ec); + else if (_ec != boost::system::errc::success && + _ec != boost::system::errc::address_not_available && + _ec != boost::system::errc::host_unreachable) + return disconnectWithError(_ec); // 49: can't assign requested address else { Guard l(x_sendQ); From b47431a328889adde92d04dd5732a9db1edccb82 Mon Sep 17 00:00:00 2001 From: subtly Date: Sun, 10 May 2015 10:17:13 +0200 Subject: [PATCH 2/2] remove misplaced comment --- libp2p/UDP.h | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/libp2p/UDP.h b/libp2p/UDP.h index 4cab9b22d..f6a4842a9 100644 --- a/libp2p/UDP.h +++ b/libp2p/UDP.h @@ -229,9 +229,9 @@ void UDPSocket::doWrite() if (m_closed) return disconnectWithError(_ec); else if (_ec != boost::system::errc::success && - _ec != boost::system::errc::address_not_available && - _ec != boost::system::errc::host_unreachable) - return disconnectWithError(_ec); // 49: can't assign requested address + _ec != boost::system::errc::address_not_available && + _ec != boost::system::errc::host_unreachable) + return disconnectWithError(_ec); else { Guard l(x_sendQ);