diff options
Diffstat (limited to 'httpd.c')
| -rw-r--r-- | httpd.c | 26 |
1 files changed, 24 insertions, 2 deletions
| @@ -10,6 +10,8 @@ | |||
| 10 | 10 | ||
| 11 | #include "snac.h" | 11 | #include "snac.h" |
| 12 | 12 | ||
| 13 | #include <setjmp.h> | ||
| 14 | |||
| 13 | /* susie.png */ | 15 | /* susie.png */ |
| 14 | const char *susie = | 16 | const char *susie = |
| 15 | "iVBORw0KGgoAAAANSUhEUgAAAEAAAABAAQAAAAC" | 17 | "iVBORw0KGgoAAAANSUhEUgAAAEAAAABAAQAAAAC" |
| @@ -188,6 +190,15 @@ void httpd_connection(int rs) | |||
| 188 | } | 190 | } |
| 189 | 191 | ||
| 190 | 192 | ||
| 193 | static jmp_buf on_break; | ||
| 194 | |||
| 195 | |||
| 196 | void term_handler(int s) | ||
| 197 | { | ||
| 198 | longjmp(on_break, 1); | ||
| 199 | } | ||
| 200 | |||
| 201 | |||
| 191 | void httpd(void) | 202 | void httpd(void) |
| 192 | /* starts the server */ | 203 | /* starts the server */ |
| 193 | { | 204 | { |
| @@ -205,11 +216,22 @@ void httpd(void) | |||
| 205 | 216 | ||
| 206 | srv_running = 1; | 217 | srv_running = 1; |
| 207 | 218 | ||
| 219 | signal(SIGPIPE, SIG_IGN); | ||
| 220 | signal(SIGTERM, term_handler); | ||
| 221 | signal(SIGINT, term_handler); | ||
| 222 | |||
| 208 | srv_log(xs_fmt("httpd start %s:%d", address, port)); | 223 | srv_log(xs_fmt("httpd start %s:%d", address, port)); |
| 209 | 224 | ||
| 210 | for (;;) { | 225 | if (setjmp(on_break) == 0) { |
| 211 | httpd_connection(rs); | 226 | for (;;) { |
| 227 | httpd_connection(rs); | ||
| 228 | } | ||
| 212 | } | 229 | } |
| 213 | 230 | ||
| 231 | srv_running = 0; | ||
| 232 | |||
| 233 | /* wait for the helper thread to end */ | ||
| 234 | /* ... */ | ||
| 235 | |||
| 214 | srv_log(xs_fmt("httpd stop %s:%d", address, port)); | 236 | srv_log(xs_fmt("httpd stop %s:%d", address, port)); |
| 215 | } | 237 | } |