diff options
author | mrfoxygmfr <mrfoxygmfr@sch9.ru> | 2025-05-21 14:04:19 +0300 |
---|---|---|
committer | mrfoxygmfr <mrfoxygmfr@sch9.ru> | 2025-05-21 14:04:19 +0300 |
commit | 42557513bc4740b65175b6ca46307ce023c2a628 (patch) | |
tree | dac40219c71b3078f67658eeb8a1d1aaf4e297ce | |
parent | 7d4e357bac40a3ef792bb9fc25c9340c5b0131d6 (diff) |
feat(lib): add function to configure timeout
-rw-r--r-- | lib/common.c | 14 | ||||
-rw-r--r-- | lib/common.h | 2 |
2 files changed, 16 insertions, 0 deletions
diff --git a/lib/common.c b/lib/common.c new file mode 100644 index 0000000..6a54108 --- /dev/null +++ b/lib/common.c @@ -0,0 +1,14 @@ +#include "./common.h" +#include <signal.h> + +void timer_handler(int signum) { + signum = signum; + + printf("Stopping due to timeout\n"); + exit(EXIT_FAILURE); +} + +void configure_timeout(int delay) { + signal(SIGALRM, timer_handler); + alarm(delay); +} diff --git a/lib/common.h b/lib/common.h index ab6c05d..cf566f0 100644 --- a/lib/common.h +++ b/lib/common.h @@ -16,4 +16,6 @@ enum { REQUEST_TYPE_PUT_RESULT, }; +void configure_timeout(int delay); + #endif // COMMON_H |