From 3759d3988b9ed344609f477942b13da8f720b0a3 Mon Sep 17 00:00:00 2001 From: Eric Saxby Date: Thu, 27 Jun 2024 10:22:47 -0700 Subject: [PATCH] Use nanosleep instead of sleep --- distrans.c | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/distrans.c b/distrans.c index ab3966f..4239395 100644 --- a/distrans.c +++ b/distrans.c @@ -1,6 +1,7 @@ #include #include #include +#include #include #include #include @@ -12,7 +13,7 @@ void implode(int socket) { close(socket); - exit(1); + exit(0); } void forbidden(int socket) { @@ -73,7 +74,10 @@ void respond(int socket, int verbose) { (void)sprintf(write_buffer,"%s", GIF); (void)write(socket, write_buffer, strlen(write_buffer)); - sleep(0.001); + struct timespec ts; + ts.tv_sec = 1 / 1000; + + nanosleep(&ts, &ts); implode(socket); } @@ -122,7 +126,7 @@ int main(int argc, char *argv[]) { socketfd = accept(listenfd, (struct sockaddr*)&cli_addr, &length); pid = fork(); - if(pid == 0) { + if (pid == 0) { (void)close(listenfd); respond(socketfd, verbose); } else if (pid > 0) {