summaryrefslogtreecommitdiff
path: root/cfws.c
diff options
context:
space:
mode:
Diffstat (limited to 'cfws.c')
-rw-r--r--cfws.c16
1 files changed, 14 insertions, 2 deletions
diff --git a/cfws.c b/cfws.c
index f280fe4..2e8eb32 100644
--- a/cfws.c
+++ b/cfws.c
@@ -11,14 +11,24 @@
#define CFWS_DEFAULT_PORT 8080
+static int serverfd;
+
static void handle_request(const struct http_request *, int);
+static void handle_sigint(int signum)
+{
+ (void)signum;
+ shutdown(serverfd, SHUT_RDWR);
+}
+
int main(int argc, char *argv[])
{
int port = CFWS_DEFAULT_PORT;
- int serverfd, clientfd;
+ int clientfd;
struct http_request request;
+ signal(SIGINT, handle_sigint);
+
/* Prevent the program from quitting if it attempts to write to a closed
* socket. */
signal(SIGPIPE, SIG_IGN);
@@ -30,7 +40,9 @@ int main(int argc, char *argv[])
printf("Serving a directory at localhost:%d\n", port);
while (1) {
- request = net_next_request(serverfd, &clientfd);
+ int rc = net_next_request(serverfd, &clientfd, &request);
+ if (rc != 0)
+ break;
handle_request(&request, clientfd);