This commit is contained in:
yhirose 2023-03-03 23:45:19 -05:00 committed by GitHub
parent cdaa5c48db
commit ba5884e779
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 67 additions and 1 deletions

View file

@ -6289,6 +6289,13 @@ inline bool ClientImpl::send(Request &req, Response &res, Error &error) {
auto is_alive = false;
if (socket_.is_open()) {
is_alive = detail::is_socket_alive(socket_.sock);
#ifdef CPPHTTPLIB_OPENSSL_SUPPORT
if (is_ssl() && is_alive) {
char buf[1];
auto n = SSL_peek(socket_.ssl, buf, 1);
if (n <= 0) { is_alive = false; }
}
#endif
if (!is_alive) {
// Attempt to avoid sigpipe by shutting down nongracefully if it seems
// like the other side has already closed the connection Also, there
@ -6339,7 +6346,7 @@ inline bool ClientImpl::send(Request &req, Response &res, Error &error) {
auto ret = false;
auto close_connection = !keep_alive_;
auto se = detail::scope_exit<std::function<void (void)>>([&]() {
auto se = detail::scope_exit<std::function<void(void)>>([&]() {
// Briefly lock mutex in order to mark that a request is no longer ongoing
std::lock_guard<std::mutex> guard(socket_mutex_);
socket_requests_in_flight_ -= 1;