From 4362eccd92ed31ddc586103bcc0f4c087f73b86d Mon Sep 17 00:00:00 2001 From: Nayan <33187059+GShadow5@users.noreply.github.com> Date: Tue, 6 May 2025 16:57:50 -0400 Subject: [PATCH] add comments to client handler --- client_handler.c | 16 ++++++++++++++++ client_handler.h | 3 +++ 2 files changed, 19 insertions(+) diff --git a/client_handler.c b/client_handler.c index a758d6a..b3cb8bc 100644 --- a/client_handler.c +++ b/client_handler.c @@ -4,7 +4,21 @@ #define BUFFER_SIZE 1024 +/** + * Handles a single client connection. + * + * @param args A pointer to the file descriptor of the client + * + * @return NULL + * + * @details + * This function is designed to be run in a separate thread. It will receive + * requests from the client until the client disconnects, at which point it will + * return. Reading the requests and building responses is handled by + * handle_request. + */ void* client_handler(void* args) { + // Cast args int client = *((int*)args); char* buffer = (char*)malloc(BUFFER_SIZE); @@ -13,9 +27,11 @@ void* client_handler(void* args) { // Null terminate buffer buffer[bytes_read] = '\0'; + // Allocate space for response char* response = (char*)malloc(BUFFER_SIZE); size_t response_length = BUFFER_SIZE; + // Handle request handle_request(buffer, bytes_read, response, &response_length); // Send response diff --git a/client_handler.h b/client_handler.h index bcddcfa..8a2750d 100644 --- a/client_handler.h +++ b/client_handler.h @@ -1,11 +1,14 @@ #ifndef CLIENT_HANDLER_H #define CLIENT_HANDLER_H +#include +#include #include #include #include #include #include +#include #include void* client_handler(void* args);