comparison src/c/driver.c @ 477:667c0e54632a

Add help text for generated web servers
author Adam Chlipala <adamc@hcoop.net>
date Sat, 08 Nov 2008 12:24:23 -0500
parents 9babc5d2ec5a
children 581554f8e642
comparison
equal deleted inserted replaced
476:c9566d49ecfe 477:667c0e54632a
290 close(sock); 290 close(sock);
291 uw_reset(ctx); 291 uw_reset(ctx);
292 } 292 }
293 } 293 }
294 294
295 static void help(char *cmd) {
296 printf("Usage: %s [-p <port>] [-t <thread-count>]\n", cmd);
297 }
298
295 int main(int argc, char *argv[]) { 299 int main(int argc, char *argv[]) {
296 // The skeleton for this function comes from Beej's sockets tutorial. 300 // The skeleton for this function comes from Beej's sockets tutorial.
297 int sockfd; // listen on sock_fd 301 int sockfd; // listen on sock_fd
298 struct sockaddr_in my_addr; 302 struct sockaddr_in my_addr;
299 struct sockaddr_in their_addr; // connector's address information 303 struct sockaddr_in their_addr; // connector's address information
300 int sin_size, yes = 1; 304 int sin_size, yes = 1;
301 int uw_port = 8080, nthreads = 1, i, *names, opt; 305 int uw_port = 8080, nthreads = 1, i, *names, opt;
302 306
303 while ((opt = getopt(argc, argv, "p:t:")) != -1) { 307 while ((opt = getopt(argc, argv, "hp:t:")) != -1) {
304 switch (opt) { 308 switch (opt) {
305 case '?': 309 case '?':
306 fprintf(stderr, "Unknown command-line option"); 310 fprintf(stderr, "Unknown command-line option");
311 help(argv[0]);
307 return 1; 312 return 1;
313
314 case 'h':
315 help(argv[0]);
316 return 0;
308 317
309 case 'p': 318 case 'p':
310 uw_port = atoi(optarg); 319 uw_port = atoi(optarg);
311 if (uw_port <= 0) { 320 if (uw_port <= 0) {
312 fprintf(stderr, "Invalid port number\n"); 321 fprintf(stderr, "Invalid port number\n");
322 help(argv[0]);
313 return 1; 323 return 1;
314 } 324 }
315 break; 325 break;
316 326
317 case 't': 327 case 't':
318 nthreads = atoi(optarg); 328 nthreads = atoi(optarg);
319 if (nthreads <= 0) { 329 if (nthreads <= 0) {
320 fprintf(stderr, "Invalid thread count\n"); 330 fprintf(stderr, "Invalid thread count\n");
331 help(argv[0]);
321 return 1; 332 return 1;
322 } 333 }
323 break; 334 break;
324 335
325 default: 336 default: