mirror of
https://codeberg.org/grunfink/snac2.git
synced 2025-02-16 16:05:00 +00:00
Added some signal control.
This commit is contained in:
parent
aabdbe1dee
commit
80d1700f6a
1 changed files with 24 additions and 2 deletions
26
httpd.c
26
httpd.c
|
@ -10,6 +10,8 @@
|
||||||
|
|
||||||
#include "snac.h"
|
#include "snac.h"
|
||||||
|
|
||||||
|
#include <setjmp.h>
|
||||||
|
|
||||||
/* susie.png */
|
/* susie.png */
|
||||||
const char *susie =
|
const char *susie =
|
||||||
"iVBORw0KGgoAAAANSUhEUgAAAEAAAABAAQAAAAC"
|
"iVBORw0KGgoAAAANSUhEUgAAAEAAAABAAQAAAAC"
|
||||||
|
@ -188,6 +190,15 @@ void httpd_connection(int rs)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
static jmp_buf on_break;
|
||||||
|
|
||||||
|
|
||||||
|
void term_handler(int s)
|
||||||
|
{
|
||||||
|
longjmp(on_break, 1);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
void httpd(void)
|
void httpd(void)
|
||||||
/* starts the server */
|
/* starts the server */
|
||||||
{
|
{
|
||||||
|
@ -205,11 +216,22 @@ void httpd(void)
|
||||||
|
|
||||||
srv_running = 1;
|
srv_running = 1;
|
||||||
|
|
||||||
|
signal(SIGPIPE, SIG_IGN);
|
||||||
|
signal(SIGTERM, term_handler);
|
||||||
|
signal(SIGINT, term_handler);
|
||||||
|
|
||||||
srv_log(xs_fmt("httpd start %s:%d", address, port));
|
srv_log(xs_fmt("httpd start %s:%d", address, port));
|
||||||
|
|
||||||
for (;;) {
|
if (setjmp(on_break) == 0) {
|
||||||
httpd_connection(rs);
|
for (;;) {
|
||||||
|
httpd_connection(rs);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
srv_running = 0;
|
||||||
|
|
||||||
|
/* wait for the helper thread to end */
|
||||||
|
/* ... */
|
||||||
|
|
||||||
srv_log(xs_fmt("httpd stop %s:%d", address, port));
|
srv_log(xs_fmt("httpd stop %s:%d", address, port));
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue