fix issue with SSL tracker connections left in CLOSE_WAIT state (#2797)

This commit is contained in:
Arvid Norberg 2018-02-20 08:40:47 +01:00 committed by GitHub
parent 0ecb935d9d
commit eec34e3ac3
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 11 additions and 1 deletions

View File

@ -1,4 +1,5 @@
* fix issue with SSL tracker connections left in CLOSE_WAIT state
* defer truncating existing files until the first time we write to them * defer truncating existing files until the first time we write to them
* fix issue when receiving a torrent with 0-sized padfiles as magnet link * fix issue when receiving a torrent with 0-sized padfiles as magnet link
* fix issue resuming 1.0.x downloads with a file priority 0 * fix issue resuming 1.0.x downloads with a file priority 0

View File

@ -139,6 +139,8 @@ namespace libtorrent
#ifdef TORRENT_USE_OPENSSL #ifdef TORRENT_USE_OPENSSL
namespace { namespace {
void nop(boost::shared_ptr<void>) {}
void on_close_socket(socket_type* s, boost::shared_ptr<void>) void on_close_socket(socket_type* s, boost::shared_ptr<void>)
{ {
#if defined TORRENT_ASIO_DEBUGGING #if defined TORRENT_ASIO_DEBUGGING
@ -165,9 +167,16 @@ namespace libtorrent
#define MAYBE_ASIO_DEBUGGING #define MAYBE_ASIO_DEBUGGING
#endif #endif
char const buffer[] = "";
// chasing the async_shutdown by a write is a trick to close the socket as
// soon as we've sent the close_notify, without having to wait to receive a
// response from the other end
// https://stackoverflow.com/questions/32046034/what-is-the-proper-way-to-securely-disconnect-an-asio-ssl-socket
#define CASE(t) case socket_type_int_impl<ssl_stream<t> >::value: \ #define CASE(t) case socket_type_int_impl<ssl_stream<t> >::value: \
MAYBE_ASIO_DEBUGGING \ MAYBE_ASIO_DEBUGGING \
s.get<ssl_stream<t> >()->async_shutdown(boost::bind(&on_close_socket, &s, holder)); \ s.get<ssl_stream<t> >()->async_shutdown(boost::bind(&nop, holder)); \
s.get<ssl_stream<t> >()->async_write_some(boost::asio::buffer(buffer), boost::bind(&on_close_socket, &s, holder)); \
break; break;
switch (s.type()) switch (s.type())