From 30231744c71dda83b37b1b480621eb4899666d02 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Markus=20Lindel=C3=B6w?= Date: Thu, 23 Apr 2026 21:35:55 +0000 Subject: [PATCH] Use close connection in readme example --- README.md | 8 ++++++-- include/tinycsocket.h | 2 +- src/tinycsocket_internal.h | 2 +- tests/tests.cpp | 9 +++++++-- 4 files changed, 15 insertions(+), 6 deletions(-) diff --git a/README.md b/README.md index 7a59fad..12eb41a 100644 --- a/README.md +++ b/README.md @@ -23,12 +23,16 @@ int main(int argc, const char* argv[]) tcs_socket(&client_socket, TCS_FAMILY_IP4, TCS_SOCK_STREAM, TCS_PROTOCOL_IP_TCP); tcs_connect_str(client_socket, "example.com", 80); - uint8_t send_buffer[] = "GET / HTTP/1.1\r\nHost: example.com\r\n\r\n"; + uint8_t send_buffer[] = + "GET / HTTP/1.1\r\n" + "Host: example.com\r\n" + "Connection: close\r\n" + "\r\n"; tcs_send(client_socket, send_buffer, sizeof(send_buffer) - 1, TCS_MSG_SENDALL, NULL); uint8_t recv_buffer[8192] = {0}; size_t bytes_received = 0; - tcs_receive(client_socket, recv_buffer, 8192, TCS_FLAG_NONE, &bytes_received); + tcs_receive(client_socket, recv_buffer, sizeof(recv_buffer), TCS_MSG_WAITALL, &bytes_received); tcs_shutdown(client_socket, TCS_SD_BOTH); tcs_close(&client_socket); diff --git a/include/tinycsocket.h b/include/tinycsocket.h index 7b71893..5a85efe 100644 --- a/include/tinycsocket.h +++ b/include/tinycsocket.h @@ -29,7 +29,7 @@ #ifndef TINYCSOCKET_INTERNAL_H_ #define TINYCSOCKET_INTERNAL_H_ -static const char* const TCS_VERSION_TXT = "v0.3.74"; +static const char* const TCS_VERSION_TXT = "v0.3.75"; static const char* const TCS_LICENSE_TXT = "Copyright 2018 Markus Lindelöw\n" "\n" diff --git a/src/tinycsocket_internal.h b/src/tinycsocket_internal.h index ce23634..5c5a808 100644 --- a/src/tinycsocket_internal.h +++ b/src/tinycsocket_internal.h @@ -23,7 +23,7 @@ #ifndef TINYCSOCKET_INTERNAL_H_ #define TINYCSOCKET_INTERNAL_H_ -static const char* const TCS_VERSION_TXT = "v0.3.74"; +static const char* const TCS_VERSION_TXT = "v0.3.75"; static const char* const TCS_LICENSE_TXT = "Copyright 2018 Markus Lindelöw\n" "\n" diff --git a/tests/tests.cpp b/tests/tests.cpp index 16b460a..4f1ce93 100644 --- a/tests/tests.cpp +++ b/tests/tests.cpp @@ -103,12 +103,17 @@ TEST_CASE("Example from README") REQUIRE(tcs_socket(&client_socket, TCS_FAMILY_IP4, TCS_SOCK_STREAM, TCS_PROTOCOL_IP_TCP) == TCS_SUCCESS); REQUIRE(tcs_connect_str(client_socket, "example.com", 80) == TCS_SUCCESS); - uint8_t send_buffer[] = "GET / HTTP/1.1\r\nHost: example.com\r\n\r\n"; + uint8_t send_buffer[] = + "GET / HTTP/1.1\r\n" + "Host: example.com\r\n" + "Connection: close\r\n" + "\r\n"; CHECK(tcs_send(client_socket, send_buffer, sizeof(send_buffer) - 1, TCS_MSG_SENDALL, NULL) == TCS_SUCCESS); static uint8_t recv_buffer[8192] = {0}; size_t bytes_received = 0; - CHECK(tcs_receive(client_socket, recv_buffer, 8192, TCS_FLAG_NONE, &bytes_received) == TCS_SUCCESS); + tcs_receive(client_socket, recv_buffer, sizeof(recv_buffer), TCS_MSG_WAITALL, &bytes_received); + CHECK(bytes_received > 0); TcsResult shutdown_res = tcs_shutdown(client_socket, TCS_SD_BOTH); CHECK((shutdown_res == TCS_SUCCESS || shutdown_res == TCS_ERROR_NOT_CONNECTED || shutdown_res == TCS_ERROR_CONNECTION_RESET || shutdown_res == TCS_ERROR_SOCKET_CLOSED));