mirror of
https://github.com/yhirose/cpp-httplib.git
synced 2025-05-12 06:01:40 +00:00
Code format
This commit is contained in:
parent
e1f781a21a
commit
726c64cf10
38
httplib.h
38
httplib.h
@ -1140,7 +1140,7 @@ private:
|
|||||||
#ifdef CPPHTTPLIB_OPENSSL_SUPPORT
|
#ifdef CPPHTTPLIB_OPENSSL_SUPPORT
|
||||||
bool is_ssl_ = false;
|
bool is_ssl_ = false;
|
||||||
#endif
|
#endif
|
||||||
}; // namespace httplib
|
};
|
||||||
|
|
||||||
#ifdef CPPHTTPLIB_OPENSSL_SUPPORT
|
#ifdef CPPHTTPLIB_OPENSSL_SUPPORT
|
||||||
class SSLServer : public Server {
|
class SSLServer : public Server {
|
||||||
@ -5660,25 +5660,21 @@ inline void ssl_delete(std::mutex &ctx_mutex, SSL *ssl,
|
|||||||
}
|
}
|
||||||
|
|
||||||
template <typename U>
|
template <typename U>
|
||||||
bool ssl_connect_or_accept_nonblocking(socket_t sock, SSL *ssl, U ssl_connect_or_accept,
|
bool ssl_connect_or_accept_nonblocking(socket_t sock, SSL *ssl,
|
||||||
time_t timeout_sec, time_t timeout_usec) {
|
U ssl_connect_or_accept,
|
||||||
|
time_t timeout_sec,
|
||||||
|
time_t timeout_usec) {
|
||||||
int res = 0;
|
int res = 0;
|
||||||
while ((res = ssl_connect_or_accept(ssl)) != 1) {
|
while ((res = ssl_connect_or_accept(ssl)) != 1) {
|
||||||
auto err = SSL_get_error(ssl, res);
|
auto err = SSL_get_error(ssl, res);
|
||||||
switch (err)
|
switch (err) {
|
||||||
{
|
|
||||||
case SSL_ERROR_WANT_READ:
|
case SSL_ERROR_WANT_READ:
|
||||||
if (select_read(sock, timeout_sec, timeout_usec) > 0) {
|
if (select_read(sock, timeout_sec, timeout_usec) > 0) { continue; }
|
||||||
continue;
|
|
||||||
}
|
|
||||||
break;
|
break;
|
||||||
case SSL_ERROR_WANT_WRITE:
|
case SSL_ERROR_WANT_WRITE:
|
||||||
if (select_write(sock, timeout_sec, timeout_usec) > 0) {
|
if (select_write(sock, timeout_sec, timeout_usec) > 0) { continue; }
|
||||||
continue;
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
break;
|
break;
|
||||||
|
default: break;
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
@ -5798,9 +5794,7 @@ inline ssize_t SSLSocketStream::read(char *ptr, size_t size) {
|
|||||||
return SSL_read(ssl_, ptr, static_cast<int>(size));
|
return SSL_read(ssl_, ptr, static_cast<int>(size));
|
||||||
} else if (is_readable()) {
|
} else if (is_readable()) {
|
||||||
ret = SSL_read(ssl_, ptr, static_cast<int>(size));
|
ret = SSL_read(ssl_, ptr, static_cast<int>(size));
|
||||||
if (ret >= 0) {
|
if (ret >= 0) { return ret; }
|
||||||
return ret;
|
|
||||||
}
|
|
||||||
err = SSL_get_error(ssl_, ret);
|
err = SSL_get_error(ssl_, ret);
|
||||||
} else {
|
} else {
|
||||||
return -1;
|
return -1;
|
||||||
@ -5902,11 +5896,10 @@ inline bool SSLServer::process_and_close_socket(socket_t sock) {
|
|||||||
auto ssl = detail::ssl_new(
|
auto ssl = detail::ssl_new(
|
||||||
sock, ctx_, ctx_mutex_,
|
sock, ctx_, ctx_mutex_,
|
||||||
[&](SSL *ssl) {
|
[&](SSL *ssl) {
|
||||||
return detail:: ssl_connect_or_accept_nonblocking(sock, ssl, SSL_accept, read_timeout_sec_, read_timeout_usec_);
|
return detail::ssl_connect_or_accept_nonblocking(
|
||||||
|
sock, ssl, SSL_accept, read_timeout_sec_, read_timeout_usec_);
|
||||||
},
|
},
|
||||||
[](SSL * /*ssl*/) {
|
[](SSL * /*ssl*/) { return true; });
|
||||||
return true;
|
|
||||||
});
|
|
||||||
|
|
||||||
if (ssl) {
|
if (ssl) {
|
||||||
auto ret = detail::process_server_socket_ssl(
|
auto ret = detail::process_server_socket_ssl(
|
||||||
@ -6100,8 +6093,9 @@ inline bool SSLClient::initialize_ssl(Socket &socket) {
|
|||||||
SSL_set_verify(ssl, SSL_VERIFY_NONE, nullptr);
|
SSL_set_verify(ssl, SSL_VERIFY_NONE, nullptr);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!detail:: ssl_connect_or_accept_nonblocking(socket.sock, ssl, SSL_connect,
|
if (!detail::ssl_connect_or_accept_nonblocking(
|
||||||
connection_timeout_sec_, connection_timeout_usec_)) {
|
socket.sock, ssl, SSL_connect, connection_timeout_sec_,
|
||||||
|
connection_timeout_usec_)) {
|
||||||
error_ = Error::SSLConnection;
|
error_ = Error::SSLConnection;
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user