From 15c95a3ec798f3f75121e59e52aa3661f847a7f5 Mon Sep 17 00:00:00 2001 From: cryptocode <34946442+cryptocode@users.noreply.github.com> Date: Fri, 14 Dec 2018 20:48:25 +0100 Subject: [PATCH] Close sockets gracefully (#1445) --- rai/node/bootstrap.cpp | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/rai/node/bootstrap.cpp b/rai/node/bootstrap.cpp index ec3513404b..941bb9f455 100644 --- a/rai/node/bootstrap.cpp +++ b/rai/node/bootstrap.cpp @@ -69,6 +69,14 @@ void rai::socket::close () { if (socket_m.is_open ()) { + try + { + socket_m.shutdown (boost::asio::ip::tcp::socket::shutdown_both); + } + catch (...) + { + /* Ignore spurious exceptions; shutdown is best effort. */ + } socket_m.close (); } }