Merge pull request #5996

23ba69e epee: fix SSL server handshake, run_one() can block, use poll_one() (xiphon)
This commit is contained in:
luigi1111 2019-10-22 10:26:31 -05:00
commit 6b58d6248a
No known key found for this signature in database
GPG Key ID: F4ACA0183641E010
2 changed files with 11 additions and 2 deletions

View File

@ -29,6 +29,7 @@
#ifndef _NET_SSL_H
#define _NET_SSL_H
#include <chrono>
#include <stdint.h>
#include <string>
#include <vector>

View File

@ -27,6 +27,7 @@
// THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#include <string.h>
#include <thread>
#include <boost/asio/ssl.hpp>
#include <boost/lambda/lambda.hpp>
#include <openssl/ssl.h>
@ -519,10 +520,17 @@ bool ssl_options_t::handshake(
boost::system::error_code ec = boost::asio::error::would_block;
socket.async_handshake(type, boost::lambda::var(ec) = boost::lambda::_1);
while (ec == boost::asio::error::would_block)
if (io_service.stopped())
{
io_service.reset();
io_service.run_one();
}
while (ec == boost::asio::error::would_block && !io_service.stopped())
{
// should poll_one(), can't run_one() because it can block if there is
// another worker thread executing io_service's tasks
// TODO: once we get Boost 1.66+, replace with run_one_for/run_until
std::this_thread::sleep_for(std::chrono::milliseconds(30));
io_service.poll_one();
}
if (ec)