Commit 17639659 authored by xiezhi's avatar xiezhi

fix

parent 731707c8
...@@ -4,6 +4,7 @@ ...@@ -4,6 +4,7 @@
#include <unistd.h> #include <unistd.h>
#include <arpa/inet.h> #include <arpa/inet.h>
#include <sys/socket.h> #include <sys/socket.h>
#include <sys/time.h>
#include <signal.h> #include <signal.h>
#include <time.h> #include <time.h>
#include <errno.h> #include <errno.h>
...@@ -15,6 +16,7 @@ volatile sig_atomic_t keep_running = 1; ...@@ -15,6 +16,7 @@ volatile sig_atomic_t keep_running = 1;
// Signal handler function // Signal handler function
void handle_signal(int sig) { void handle_signal(int sig) {
(void)sig; // Suppress unused parameter warning
keep_running = 0; keep_running = 0;
} }
...@@ -73,9 +75,9 @@ int main() { ...@@ -73,9 +75,9 @@ int main() {
exit(EXIT_FAILURE); exit(EXIT_FAILURE);
} }
// Set socket options to reuse address and port // Set socket options to reuse address
int opt = 1; int opt = 1;
if (setsockopt(server_fd, SOL_SOCKET, SO_REUSEADDR | SO_REUSEPORT, &opt, sizeof(opt))) { if (setsockopt(server_fd, SOL_SOCKET, SO_REUSEADDR, &opt, sizeof(opt))) {
perror("setsockopt failed"); perror("setsockopt failed");
exit(EXIT_FAILURE); exit(EXIT_FAILURE);
} }
...@@ -124,8 +126,11 @@ int main() { ...@@ -124,8 +126,11 @@ int main() {
get_time_string(time_buffer, sizeof(time_buffer)); get_time_string(time_buffer, sizeof(time_buffer));
printf("[%s] Request from %s\n", time_buffer, client_ip); printf("[%s] Request from %s\n", time_buffer, client_ip);
read(new_socket, buffer, BUFFER_SIZE); ssize_t bytes_read = read(new_socket, buffer, BUFFER_SIZE);
write(new_socket, http_response, strlen(http_response)); (void)bytes_read; // Suppress unused variable warning
ssize_t bytes_written = write(new_socket, http_response, strlen(http_response));
(void)bytes_written; // Suppress unused variable warning
close(new_socket); close(new_socket);
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment