Develop (#13)
* Refactor carbon-server service in docker-compose.yml to use pre-built image and remove unnecessary build context and volume mounts * Enhance performance and security features: - Update compiler flags for better optimization and security. - Implement MIME type caching for improved response handling. - Introduce worker thread pool for efficient connection management. - Optimize socket settings for low latency and enhanced performance. - Add support for CPU affinity in worker threads. - Implement graceful shutdown for worker threads during cleanup. * Optimize HTTP response handling and increase request limits for improved performance * Add gzip compression support for HTTP responses * Implement Keep-Alive support for HTTP connections with timeout handling Why is it not merging like this huh
This commit is contained in:
22
src/server.c
22
src/server.c
@@ -569,6 +569,20 @@ void *handle_http_client(void *arg)
|
||||
pthread_exit(NULL);
|
||||
}
|
||||
|
||||
// Set socket timeout for Keep-Alive (5 seconds)
|
||||
struct timeval timeout;
|
||||
timeout.tv_sec = 5;
|
||||
timeout.tv_usec = 0;
|
||||
setsockopt(client_socket, SOL_SOCKET, SO_RCVTIMEO, &timeout, sizeof(timeout));
|
||||
|
||||
int keep_alive_count = 0;
|
||||
const int max_keep_alive = 100;
|
||||
|
||||
// Keep-Alive loop: handle multiple requests on same connection
|
||||
while (server_running && keep_alive_count < max_keep_alive)
|
||||
{
|
||||
keep_alive_count++;
|
||||
|
||||
char request_buffer[MAX_REQUEST_SIZE];
|
||||
memset(request_buffer, 0, MAX_REQUEST_SIZE);
|
||||
ssize_t bytes_received = recv(client_socket, request_buffer, MAX_REQUEST_SIZE - 1, 0);
|
||||
@@ -844,10 +858,16 @@ void *handle_http_client(void *arg)
|
||||
}
|
||||
|
||||
done_serving:
|
||||
continue;
|
||||
}
|
||||
else if (bytes_received < 0)
|
||||
{
|
||||
HANDLE_ERROR("Error receiving request");
|
||||
break;
|
||||
}
|
||||
else if (bytes_received == 0)
|
||||
{
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
close(client_socket);
|
||||
|
||||
Reference in New Issue
Block a user