5 * oserver - a demonstration module for LCA2011
7 * This code shows off the features of CCAN and various C cantrips.
12 * #include <sys/types.h>
13 * #include <sys/socket.h>
14 * #include <ccan/oserver/oserver.h>
15 * #include <ccan/opt/opt.h>
19 * int main(int argc, char *argv[])
22 * unsigned int port = OSERVER_PORT;
24 * opt_register_noarg("--help|--usage|-h", opt_usage_and_exit,
25 * "\nA oserver program", "Usage information");
26 * opt_register_arg("--port", opt_set_uintval, opt_show_uintval,
27 * &port, "Server port number");
29 * opt_parse(&argc, argv, opt_log_stderr_exit);
31 * opt_log_stderr_exit("Unknown extra arguments");
33 * sockfd = oserver_setup(port);
35 * err(1, "Failed to set up server socket");
37 * fd = accept(sockfd, NULL, NULL);
39 * err(1, "Accepting connection on TCP socket");
41 * if (!oserver_serve(fd))
42 * err(1, "Serving client");
46 int main(int argc, char *argv[])
48 /* Expect exactly one argument */
52 if (strcmp(argv[1], "depends") == 0) {
53 printf("ccan/read_write_all\n");
55 printf("ccan/foreach\n");
56 printf("ccan/noerr\n");
57 printf("ccan/failtest\n");