]> git.ozlabs.org Git - ccan-lca-2011.git/blob - ccan/oserver/_info
6879f42903aa2bcab42523c330ccb3a1ae9bae03
[ccan-lca-2011.git] / ccan / oserver / _info
1 #include <string.h>
2 #include "config.h"
3
4 /**
5  * oserver - a demonstration module for LCA2011
6  *
7  * This code shows off the features of CCAN and various C cantrips.
8  *
9  * License: GPL
10  *
11  * Example:
12  *      #include <sys/types.h>
13  *      #include <sys/socket.h>
14  *      #include <ccan/oserver/oserver.h>
15  *      #include <ccan/opt/opt.h>
16  *      #include <err.h>
17  *      #include <stdlib.h>
18  *
19  *      int main(int argc, char *argv[])
20  *      {
21  *              int fd, sockfd;
22  *              unsigned int port = OSERVER_PORT;
23  *
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");
28  *
29  *              opt_parse(&argc, argv, opt_log_stderr_exit);
30  *              if (argc != 1)
31  *                      opt_log_stderr_exit("Unknown extra arguments");
32  *
33  *              sockfd = oserver_setup(port);
34  *              if (sockfd < 0)
35  *                      err(1, "Failed to set up server socket");
36  *
37  *              fd = accept(sockfd, NULL, NULL);
38  *              if (fd < 0)
39  *                      err(1, "Accepting connection on TCP socket");
40  *
41  *              if (!oserver_serve(fd))
42  *                      err(1, "Serving client");
43  *              exit(0);
44  *      }
45  */
46 int main(int argc, char *argv[])
47 {
48         /* Expect exactly one argument */
49         if (argc != 2)
50                 return 1;
51
52         if (strcmp(argv[1], "depends") == 0) {
53                 printf("ccan/read_write_all\n");
54                 printf("ccan/str\n");
55                 printf("ccan/foreach\n");
56                 printf("ccan/noerr\n");
57                 printf("ccan/failtest\n");
58                 printf("ccan/opt\n");
59                 return 0;
60         }
61
62         return 1;
63 }