Skip to content
This repository was archived by the owner on Apr 30, 2025. It is now read-only.

Commit 743ecbd

Browse files
authored
Issue1121 (yhirose#1122)
* Fixed test/Makefile problem when cleaning *.pem files * Fix yhirose#1121
1 parent 084c643 commit 743ecbd

File tree

2 files changed

+18
-15
lines changed

2 files changed

+18
-15
lines changed

httplib.h

Lines changed: 17 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -2406,12 +2406,14 @@ inline bool keep_alive(socket_t sock, time_t keep_alive_timeout_sec) {
24062406

24072407
template <typename T>
24082408
inline bool
2409-
process_server_socket_core(socket_t sock, size_t keep_alive_max_count,
2409+
process_server_socket_core(const std::atomic<socket_t> &svr_sock, socket_t sock,
2410+
size_t keep_alive_max_count,
24102411
time_t keep_alive_timeout_sec, T callback) {
24112412
assert(keep_alive_max_count > 0);
24122413
auto ret = false;
24132414
auto count = keep_alive_max_count;
2414-
while (count > 0 && keep_alive(sock, keep_alive_timeout_sec)) {
2415+
while (svr_sock != INVALID_SOCKET && count > 0 &&
2416+
keep_alive(sock, keep_alive_timeout_sec)) {
24152417
auto close_connection = count == 1;
24162418
auto connection_closed = false;
24172419
ret = callback(close_connection, connection_closed);
@@ -2423,12 +2425,13 @@ process_server_socket_core(socket_t sock, size_t keep_alive_max_count,
24232425

24242426
template <typename T>
24252427
inline bool
2426-
process_server_socket(socket_t sock, size_t keep_alive_max_count,
2428+
process_server_socket(const std::atomic<socket_t> &svr_sock, socket_t sock,
2429+
size_t keep_alive_max_count,
24272430
time_t keep_alive_timeout_sec, time_t read_timeout_sec,
24282431
time_t read_timeout_usec, time_t write_timeout_sec,
24292432
time_t write_timeout_usec, T callback) {
24302433
return process_server_socket_core(
2431-
sock, keep_alive_max_count, keep_alive_timeout_sec,
2434+
svr_sock, sock, keep_alive_max_count, keep_alive_timeout_sec,
24322435
[&](bool close_connection, bool &connection_closed) {
24332436
SocketStream strm(sock, read_timeout_sec, read_timeout_usec,
24342437
write_timeout_sec, write_timeout_usec);
@@ -5540,8 +5543,9 @@ inline bool Server::is_valid() const { return true; }
55405543

55415544
inline bool Server::process_and_close_socket(socket_t sock) {
55425545
auto ret = detail::process_server_socket(
5543-
sock, keep_alive_max_count_, keep_alive_timeout_sec_, read_timeout_sec_,
5544-
read_timeout_usec_, write_timeout_sec_, write_timeout_usec_,
5546+
svr_sock_, sock, keep_alive_max_count_, keep_alive_timeout_sec_,
5547+
read_timeout_sec_, read_timeout_usec_, write_timeout_sec_,
5548+
write_timeout_usec_,
55455549
[this](Stream &strm, bool close_connection, bool &connection_closed) {
55465550
return process_request(strm, close_connection, connection_closed,
55475551
nullptr);
@@ -6904,14 +6908,13 @@ bool ssl_connect_or_accept_nonblocking(socket_t sock, SSL *ssl,
69046908
}
69056909

69066910
template <typename T>
6907-
inline bool
6908-
process_server_socket_ssl(SSL *ssl, socket_t sock, size_t keep_alive_max_count,
6909-
time_t keep_alive_timeout_sec,
6910-
time_t read_timeout_sec, time_t read_timeout_usec,
6911-
time_t write_timeout_sec, time_t write_timeout_usec,
6912-
T callback) {
6911+
inline bool process_server_socket_ssl(
6912+
const std::atomic<socket_t> &svr_sock, SSL *ssl, socket_t sock,
6913+
size_t keep_alive_max_count, time_t keep_alive_timeout_sec,
6914+
time_t read_timeout_sec, time_t read_timeout_usec, time_t write_timeout_sec,
6915+
time_t write_timeout_usec, T callback) {
69136916
return process_server_socket_core(
6914-
sock, keep_alive_max_count, keep_alive_timeout_sec,
6917+
svr_sock, sock, keep_alive_max_count, keep_alive_timeout_sec,
69156918
[&](bool close_connection, bool &connection_closed) {
69166919
SSLSocketStream strm(sock, ssl, read_timeout_sec, read_timeout_usec,
69176920
write_timeout_sec, write_timeout_usec);
@@ -7170,7 +7173,7 @@ inline bool SSLServer::process_and_close_socket(socket_t sock) {
71707173
bool ret = false;
71717174
if (ssl) {
71727175
ret = detail::process_server_socket_ssl(
7173-
ssl, sock, keep_alive_max_count_, keep_alive_timeout_sec_,
7176+
svr_sock_, ssl, sock, keep_alive_max_count_, keep_alive_timeout_sec_,
71747177
read_timeout_sec_, read_timeout_usec_, write_timeout_sec_,
71757178
write_timeout_usec_,
71767179
[this, ssl](Stream &strm, bool close_connection,

test/Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,4 +68,4 @@ cert.pem:
6868
#c_rehash .
6969

7070
clean:
71-
rm -f test test_split test_proxy server_fuzzer pem *.0 *.o *.1 *.srl httplib.h httplib.cc
71+
rm -f test test_split test_proxy server_fuzzer *.pem *.0 *.o *.1 *.srl httplib.h httplib.cc

0 commit comments

Comments
 (0)