Skip to content

Commit 01313fb

Browse files
committed
Making socket shutdown explicit.
We want to make sure that while connections are still open to remote servers, we shut the socket down before closing it when the socket object is destroyed.
1 parent a947e52 commit 01313fb

File tree

1 file changed

+15
-6
lines changed

1 file changed

+15
-6
lines changed

boost/network/protocol/http/impl/sync_connection_base.hpp

+15-6
Original file line numberDiff line numberDiff line change
@@ -224,12 +224,14 @@ namespace boost { namespace network { namespace http { namespace impl {
224224

225225
void close_socket() {
226226
if (is_open()) {
227-
socket_.lowest_layer().shutdown(boost::asio::ip::tcp::socket::shutdown_both);
228-
socket_.lowest_layer().close();
227+
boost::system::error_code ignored;
228+
socket_.lowest_layer().shutdown(boost::asio::ip::tcp::socket::shutdown_both, ignored);
229229
}
230230
}
231231

232-
~https_sync_connection() {}
232+
~https_sync_connection() {
233+
close_socket();
234+
}
233235

234236
private:
235237
resolver_type & resolver_;
@@ -250,8 +252,6 @@ namespace boost { namespace network { namespace http { namespace impl {
250252
http_sync_connection(resolver_type & resolver, resolver_function_type resolve)
251253
: connection_base(), resolver_(resolver), resolve_(resolve), socket_(resolver.io_service()) { }
252254

253-
~http_sync_connection() {}
254-
255255
void init_socket(string_type const & hostname, string_type const & port) {
256256
connection_base::init_socket(socket_, resolver_, hostname, port, resolve_);
257257
}
@@ -276,7 +276,16 @@ namespace boost { namespace network { namespace http { namespace impl {
276276

277277
bool is_open() { return socket_.is_open(); }
278278

279-
void close_socket() { if (is_open()) { socket_.shutdown(boost::asio::ip::tcp::socket::shutdown_both); socket_.close(); } }
279+
void close_socket() {
280+
if (is_open()) {
281+
boost::system::error_code ignored;
282+
socket_.shutdown(boost::asio::ip::tcp::socket::shutdown_both, ignored);
283+
}
284+
}
285+
286+
~http_sync_connection() {
287+
close_socket();
288+
}
280289

281290
private:
282291

0 commit comments

Comments
 (0)