@@ -8541,25 +8541,33 @@ inline SSL *ssl_new(socket_t sock, SSL_CTX *ctx, std::mutex &ctx_mutex,
8541
8541
return ssl;
8542
8542
}
8543
8543
8544
- inline void ssl_delete (std::mutex &ctx_mutex, SSL *ssl,
8544
+ inline void ssl_delete (std::mutex &ctx_mutex, SSL *ssl, socket_t sock,
8545
8545
bool shutdown_gracefully) {
8546
8546
// sometimes we may want to skip this to try to avoid SIGPIPE if we know
8547
8547
// the remote has closed the network connection
8548
8548
// Note that it is not always possible to avoid SIGPIPE, this is merely a
8549
8549
// best-efforts.
8550
8550
if (shutdown_gracefully) {
8551
+ #ifdef _WIN32
8552
+ SSL_shutdown (ssl);
8553
+ #else
8551
8554
auto is_peer_could_be_closed = false ;
8552
8555
{
8556
+ timeval tv;
8557
+ tv.tv_sec = 1 ;
8558
+ tv.tv_usec = 0 ;
8559
+ setsockopt (sock, SOL_SOCKET, SO_RCVTIMEO,
8560
+ reinterpret_cast <const void *>(&tv), sizeof (tv));
8561
+
8553
8562
char buf[1 ];
8554
8563
if (SSL_peek (ssl, buf, 1 ) == 0 &&
8555
8564
SSL_get_error (ssl, 0 ) == SSL_ERROR_ZERO_RETURN) {
8556
8565
is_peer_could_be_closed = true ;
8557
8566
}
8558
8567
}
8559
8568
8560
- if (!is_peer_could_be_closed) {
8561
- SSL_shutdown (ssl);
8562
- }
8569
+ if (!is_peer_could_be_closed) { SSL_shutdown (ssl); }
8570
+ #endif
8563
8571
}
8564
8572
8565
8573
std::lock_guard<std::mutex> guard (ctx_mutex);
@@ -8839,7 +8847,7 @@ inline bool SSLServer::process_and_close_socket(socket_t sock) {
8839
8847
// Shutdown gracefully if the result seemed successful, non-gracefully if
8840
8848
// the connection appeared to be closed.
8841
8849
const bool shutdown_gracefully = ret;
8842
- detail::ssl_delete (ctx_mutex_, ssl, shutdown_gracefully);
8850
+ detail::ssl_delete (ctx_mutex_, ssl, sock, shutdown_gracefully);
8843
8851
}
8844
8852
8845
8853
detail::shutdown_socket (sock);
@@ -9122,7 +9130,8 @@ inline void SSLClient::shutdown_ssl_impl(Socket &socket,
9122
9130
return ;
9123
9131
}
9124
9132
if (socket.ssl ) {
9125
- detail::ssl_delete (ctx_mutex_, socket.ssl , shutdown_gracefully);
9133
+ detail::ssl_delete (ctx_mutex_, socket.ssl , socket.sock ,
9134
+ shutdown_gracefully);
9126
9135
socket.ssl = nullptr ;
9127
9136
}
9128
9137
assert (socket.ssl == nullptr );
0 commit comments