Compare commits

...

5 Commits

Author SHA1 Message Date
yhirose af56b7ec0b Release v0.16.3 2024-08-17 09:53:26 -04:00
Jiwoo Park 6c3e8482f7 Fix KeepAliveTest.SSLClientReconnectionPost (#1895) 2024-08-10 07:19:59 -04:00
yhirose 390f2c41f6 Fix #1878 (#1893)
* Fix #1878
2024-08-08 22:07:46 -04:00
yhirose aa04feebb4 Fix warnings 2024-08-08 20:54:33 -04:00
yhirose 45f3694f82 Fix problem with clean command in Makefile 2024-08-08 19:30:46 -04:00
3 changed files with 25 additions and 15 deletions
+1 -1
View File
@@ -58,4 +58,4 @@ pem:
openssl req -new -key key.pem | openssl x509 -days 3650 -req -signkey key.pem > cert.pem
clean:
rm server client hello simplecli simplesvr upload redirect ssesvr ssecli benchmark *.pem
rm server client hello simplecli simplesvr upload redirect ssesvr ssecli benchmark one_time_request *.pem
+13 -6
View File
@@ -8,7 +8,7 @@
#ifndef CPPHTTPLIB_HTTPLIB_H
#define CPPHTTPLIB_HTTPLIB_H
#define CPPHTTPLIB_VERSION "0.16.2"
#define CPPHTTPLIB_VERSION "0.16.3"
/*
* Configuration
@@ -3278,7 +3278,8 @@ socket_t create_socket(const std::string &host, const std::string &ip, int port,
if (socket_options) { socket_options(sock); }
if (!bind_or_connect(sock, hints)) {
bool dummy;
if (!bind_or_connect(sock, hints, dummy)) {
close_socket(sock);
sock = INVALID_SOCKET;
}
@@ -3363,12 +3364,15 @@ socket_t create_socket(const std::string &host, const std::string &ip, int port,
}
// bind or connect
if (bind_or_connect(sock, *rp)) {
auto quit = false;
if (bind_or_connect(sock, *rp, quit)) {
freeaddrinfo(result);
return sock;
}
close_socket(sock);
if (quit) { break; }
}
freeaddrinfo(result);
@@ -3469,7 +3473,7 @@ inline socket_t create_client_socket(
time_t write_timeout_usec, const std::string &intf, Error &error) {
auto sock = create_socket(
host, ip, port, address_family, 0, tcp_nodelay, std::move(socket_options),
[&](socket_t sock2, struct addrinfo &ai) -> bool {
[&](socket_t sock2, struct addrinfo &ai, bool &quit) -> bool {
if (!intf.empty()) {
#ifdef USE_IF2IP
auto ip_from_if = if2ip(address_family, intf);
@@ -3493,7 +3497,10 @@ inline socket_t create_client_socket(
}
error = wait_until_socket_is_ready(sock2, connection_timeout_sec,
connection_timeout_usec);
if (error != Error::Success) { return false; }
if (error != Error::Success) {
if (error == Error::ConnectionTimeout) { quit = true; }
return false;
}
}
set_nonblocking(sock2, false);
@@ -6470,7 +6477,7 @@ Server::create_server_socket(const std::string &host, int port,
return detail::create_socket(
host, std::string(), port, address_family_, socket_flags, tcp_nodelay_,
std::move(socket_options),
[](socket_t sock, struct addrinfo &ai) -> bool {
[](socket_t sock, struct addrinfo &ai, bool & /*quit*/) -> bool {
if (::bind(sock, ai.ai_addr, static_cast<socklen_t>(ai.ai_addrlen))) {
return false;
}
+11 -8
View File
@@ -5167,8 +5167,14 @@ TEST(KeepAliveTest, SSLClientReconnectionPost) {
res.set_content("Hello World!", "text/plain");
});
auto f = std::async(std::launch::async, [&svr] { svr.listen(HOST, PORT); });
std::this_thread::sleep_for(std::chrono::milliseconds(200));
auto listen_thread = std::thread([&svr] { svr.listen(HOST, PORT); });
auto se = detail::scope_exit([&] {
svr.stop();
listen_thread.join();
ASSERT_FALSE(svr.is_running());
});
svr.wait_until_ready();
SSLClient cli(HOST, PORT);
cli.enable_server_certificate_verification(false);
@@ -5176,7 +5182,7 @@ TEST(KeepAliveTest, SSLClientReconnectionPost) {
auto result = cli.Post(
"/hi", content.size(),
[&content](size_t offset, size_t length, DataSink &sink) {
[&content](size_t /*offset*/, size_t /*length*/, DataSink &sink) {
sink.write(content.c_str(), content.size());
return true;
},
@@ -5189,7 +5195,7 @@ TEST(KeepAliveTest, SSLClientReconnectionPost) {
// Recoonect
result = cli.Post(
"/hi", content.size(),
[&content](size_t offset, size_t length, DataSink &sink) {
[&content](size_t /*offset*/, size_t /*length*/, DataSink &sink) {
sink.write(content.c_str(), content.size());
return true;
},
@@ -5199,16 +5205,13 @@ TEST(KeepAliveTest, SSLClientReconnectionPost) {
result = cli.Post(
"/hi", content.size(),
[&content](size_t offset, size_t length, DataSink &sink) {
[&content](size_t /*offset*/, size_t /*length*/, DataSink &sink) {
sink.write(content.c_str(), content.size());
return true;
},
"text/plain");
ASSERT_TRUE(result);
EXPECT_EQ(200, result->status);
svr.stop();
f.wait();
}
#endif