From b536cd4ab4388396cd1bfc59275c43a7e248e1df Mon Sep 17 00:00:00 2001 From: Thomas Yuan Date: Fri, 13 Nov 2015 14:27:13 -0500 Subject: [PATCH] Fix iOS dead loop issue. --- src/udp_socket.cpp | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/src/udp_socket.cpp b/src/udp_socket.cpp index d8453b3f0..9a2481119 100644 --- a/src/udp_socket.cpp +++ b/src/udp_socket.cpp @@ -311,6 +311,16 @@ void udp_socket::on_read(error_code const& ec, udp::socket* s) if (err == boost::asio::error::would_block || err == boost::asio::error::try_again) break; on_read_impl(ep, err, bytes_transferred); + + // found on iOS, socket will be disconnected when app goes backgroud. try to reopen it. + if (err == boost::asio::error::not_connected || err == boost::asio::error::bad_descriptor) + { + ep = s->local_endpoint(err); + if (!err) { + bind(ep, err); + } + return; + } } call_drained_handler(); setup_read(s);