hermes

HTTP GET/HEAD-only web server for static content.
git clone git://git.francescosaccone.com/hermes
Log | Files | Refs | README | LICENSE

commit 596ea464e0f0c2e519c276c3a7b151667709f098
parent b69eadbf1c65871565b26d85b14c766ad5bcd7cb
Author: Francesco Saccone <francesco@francescosaccone.com>
Date:   Mon, 31 Mar 2025 14:46:53 +0200

fix: return status code of read_client_request function

Signed-off-by: Francesco Saccone <francesco@francescosaccone.com>

Diffstat:
Msocket.c | 10++++++----
Msocket.h | 5+++--
2 files changed, 9 insertions(+), 6 deletions(-)

diff --git a/socket.c b/socket.c @@ -52,13 +52,13 @@ accept_client(int server_socket_fd) { return client_socket_fd; } -void +int read_client_request(int client_socket_fd, char *buffer, unsigned int buffer_size) { if (buffer == NULL || buffer_size == 0) { critical("error: invalid buffer provided in read_client_request"); - return; + return -1; } memset(buffer, 0, buffer_size); @@ -69,13 +69,15 @@ read_client_request(int client_socket_fd, 0); if (bytes_received <= 0) { - return; + return -1; } if (bytes_received < buffer_size) { buffer[bytes_received] = '\0'; - return; + return -1; } buffer[buffer_size - 1] = '\0'; + + return 0; } diff --git a/socket.h b/socket.h @@ -15,8 +15,9 @@ close_socket(int socket_fd); int accept_client(int server_socket_fd); -/* writes the client request to a buffer */ -void +/* writes the client request to a buffer, returns -1 in case of an error and 0 + otherwise */ +int read_client_request(int client_socket_fd, char *buffer, unsigned int buffer_size);