diff src/c/driver.c @ 502:8875ff2e85dc

Profiling support
author Adam Chlipala <adamc@hcoop.net>
date Thu, 20 Nov 2008 12:16:30 -0500
parents 581554f8e642
children e18c747dd945
line wrap: on
line diff
--- a/src/c/driver.c	Thu Nov 20 11:34:36 2008 -0500
+++ b/src/c/driver.c	Thu Nov 20 12:16:30 2008 -0500
@@ -1,10 +1,12 @@
 #include <stdio.h>
 
 #include <string.h>
+#include <stdlib.h>
 #include <sys/types.h>
 #include <sys/socket.h>
 #include <netinet/in.h>
 #include <unistd.h>
+#include <signal.h>
 
 #include <pthread.h>
 
@@ -297,6 +299,11 @@
   printf("Usage: %s [-p <port>] [-t <thread-count>]\n", cmd);
 }
 
+static void sigint(int signum) {
+  printf("Exiting....\n");
+  exit(0);
+}
+
 int main(int argc, char *argv[]) {
   // The skeleton for this function comes from Beej's sockets tutorial.
   int sockfd;  // listen on sock_fd
@@ -304,7 +311,9 @@
   struct sockaddr_in their_addr; // connector's address information
   int sin_size, yes = 1;
   int uw_port = 8080, nthreads = 1, i, *names, opt;
-  
+ 
+  signal(SIGINT, sigint);
+ 
   while ((opt = getopt(argc, argv, "hp:t:")) != -1) {
     switch (opt) {
     case '?':