|
@@ -1871,14 +1871,14 @@ inline bool keep_alive(socket_t sock) {
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
-template <typename T, typename U>
|
|
|
|
|
|
|
+template <typename T>
|
|
|
inline bool process_server_socket_core(socket_t sock,
|
|
inline bool process_server_socket_core(socket_t sock,
|
|
|
size_t keep_alive_max_count,
|
|
size_t keep_alive_max_count,
|
|
|
- T is_shutting_down, U callback) {
|
|
|
|
|
|
|
+ T callback) {
|
|
|
assert(keep_alive_max_count > 0);
|
|
assert(keep_alive_max_count > 0);
|
|
|
auto ret = false;
|
|
auto ret = false;
|
|
|
auto count = keep_alive_max_count;
|
|
auto count = keep_alive_max_count;
|
|
|
- while (count > 0 && keep_alive(sock, is_shutting_down)) {
|
|
|
|
|
|
|
+ while (count > 0 && keep_alive(sock)) {
|
|
|
auto close_connection = count == 1;
|
|
auto close_connection = count == 1;
|
|
|
auto connection_closed = false;
|
|
auto connection_closed = false;
|
|
|
ret = callback(close_connection, connection_closed);
|
|
ret = callback(close_connection, connection_closed);
|
|
@@ -1888,14 +1888,14 @@ inline bool process_server_socket_core(socket_t sock,
|
|
|
return ret;
|
|
return ret;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
-template <typename T, typename U>
|
|
|
|
|
|
|
+template <typename T>
|
|
|
inline bool
|
|
inline bool
|
|
|
process_server_socket(socket_t sock, size_t keep_alive_max_count,
|
|
process_server_socket(socket_t sock, size_t keep_alive_max_count,
|
|
|
time_t read_timeout_sec, time_t read_timeout_usec,
|
|
time_t read_timeout_sec, time_t read_timeout_usec,
|
|
|
time_t write_timeout_sec, time_t write_timeout_usec,
|
|
time_t write_timeout_sec, time_t write_timeout_usec,
|
|
|
- T is_shutting_down, U callback) {
|
|
|
|
|
|
|
+ T callback) {
|
|
|
return process_server_socket_core(
|
|
return process_server_socket_core(
|
|
|
- sock, keep_alive_max_count, is_shutting_down,
|
|
|
|
|
|
|
+ sock, keep_alive_max_count,
|
|
|
[&](bool close_connection, bool connection_closed) {
|
|
[&](bool close_connection, bool connection_closed) {
|
|
|
SocketStream strm(sock, read_timeout_sec, read_timeout_usec,
|
|
SocketStream strm(sock, read_timeout_sec, read_timeout_usec,
|
|
|
write_timeout_sec, write_timeout_usec);
|
|
write_timeout_sec, write_timeout_usec);
|
|
@@ -4335,7 +4335,6 @@ inline bool Server::process_and_close_socket(socket_t sock) {
|
|
|
auto ret = detail::process_server_socket(
|
|
auto ret = detail::process_server_socket(
|
|
|
sock, keep_alive_max_count_, read_timeout_sec_, read_timeout_usec_,
|
|
sock, keep_alive_max_count_, read_timeout_sec_, read_timeout_usec_,
|
|
|
write_timeout_sec_, write_timeout_usec_,
|
|
write_timeout_sec_, write_timeout_usec_,
|
|
|
- [this]() { return this->svr_sock_ == INVALID_SOCKET; },
|
|
|
|
|
[this](Stream &strm, bool close_connection, bool &connection_closed) {
|
|
[this](Stream &strm, bool close_connection, bool &connection_closed) {
|
|
|
return process_request(strm, close_connection, connection_closed,
|
|
return process_request(strm, close_connection, connection_closed,
|
|
|
nullptr);
|
|
nullptr);
|
|
@@ -5177,9 +5176,9 @@ inline bool
|
|
|
process_server_socket_ssl(SSL *ssl, socket_t sock, size_t keep_alive_max_count,
|
|
process_server_socket_ssl(SSL *ssl, socket_t sock, size_t keep_alive_max_count,
|
|
|
time_t read_timeout_sec, time_t read_timeout_usec,
|
|
time_t read_timeout_sec, time_t read_timeout_usec,
|
|
|
time_t write_timeout_sec, time_t write_timeout_usec,
|
|
time_t write_timeout_sec, time_t write_timeout_usec,
|
|
|
- std::function<bool()> is_shutting_down, T callback) {
|
|
|
|
|
|
|
+ T callback) {
|
|
|
return process_server_socket_core(
|
|
return process_server_socket_core(
|
|
|
- sock, keep_alive_max_count, is_shutting_down,
|
|
|
|
|
|
|
+ sock, keep_alive_max_count,
|
|
|
[&](bool close_connection, bool connection_closed) {
|
|
[&](bool close_connection, bool connection_closed) {
|
|
|
SSLSocketStream strm(sock, ssl, read_timeout_sec, read_timeout_usec,
|
|
SSLSocketStream strm(sock, ssl, read_timeout_sec, read_timeout_usec,
|
|
|
write_timeout_sec, write_timeout_usec);
|
|
write_timeout_sec, write_timeout_usec);
|
|
@@ -5371,7 +5370,6 @@ inline bool SSLServer::process_and_close_socket(socket_t sock) {
|
|
|
auto ret = detail::process_server_socket_ssl(
|
|
auto ret = detail::process_server_socket_ssl(
|
|
|
ssl, sock, keep_alive_max_count_, read_timeout_sec_, read_timeout_usec_,
|
|
ssl, sock, keep_alive_max_count_, read_timeout_sec_, read_timeout_usec_,
|
|
|
write_timeout_sec_, write_timeout_usec_,
|
|
write_timeout_sec_, write_timeout_usec_,
|
|
|
- [this]() { return this->svr_sock_ == INVALID_SOCKET; },
|
|
|
|
|
[this, ssl](Stream &strm, bool close_connection,
|
|
[this, ssl](Stream &strm, bool close_connection,
|
|
|
bool &connection_closed) {
|
|
bool &connection_closed) {
|
|
|
return process_request(strm, close_connection, connection_closed,
|
|
return process_request(strm, close_connection, connection_closed,
|