From: Christian Heller Date: Mon, 31 Mar 2014 02:12:58 +0000 (+0200) Subject: Server: Poll server/in only every 0.33 seconds to reduce CPU usage. X-Git-Tag: tce~790 X-Git-Url: https://plomlompom.com/repos/%7B%7Bprefix%7D%7D/%7B%7B%20web_path%20%7D%7D/%7B%7Bdb.prefix%7D%7D/do_day?a=commitdiff_plain;h=7045b6f03025dfd0fecdd562fc267765a0072d6e;p=plomrogue Server: Poll server/in only every 0.33 seconds to reduce CPU usage. --- diff --git a/TODO b/TODO index b90cb76..42c0e9a 100644 --- a/TODO +++ b/TODO @@ -11,8 +11,6 @@ BOTH SERVER/CLIENT: - in textfield_width(), handle too large lines somehow -- use select() polling where possible for server-client communication - - may err_line store the processed line internally as it does the line count SERVER: diff --git a/src/server/io.c b/src/server/io.c index 28c76b8..ba5abd5 100644 --- a/src/server/io.c +++ b/src/server/io.c @@ -1,5 +1,6 @@ /* src/server/io.c */ +#define _BSD_SOURCE /* usleep() */ #include "io.h" #include /* global errno */ #include /* PIPE_BUF */ @@ -10,6 +11,7 @@ #include /* strlen(), memcpy() */ #include /* time_t */ #include /* time() */ +#include /* usleep() */ #include "../common/err_try_fgets.h" /* err_line() */ #include "../common/readwrite.h" /* try_fopen(), try_fclose_unlink_rename(), * try_fwrite(), try_fputc(), try_fgetc() @@ -94,6 +96,7 @@ static void read_file_into_queue() int test; while (EOF == (test = try_fgetc(world.file_in, f_name))) { + usleep(33); if (time(0) > now + wait_seconds) { return;