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 * #define STATE_FILE "/var/run/oserver/dump"
21 * int main(int argc, char *argv[])
23 * struct tevent_context *ev = tevent_context_init(NULL);
24 * unsigned int port = OSERVER_PORT;
25 * bool restore = false;
26 * char **restore_argv;
28 * // Save args before opt_parse mangles them.
29 * restore_argv = talloc_array(NULL, char *, argc+2);
30 * restore_argv[0] = argv[0];
31 * restore_argv[1] = "--restore";
32 * memcpy(restore_argv+2, argv+1, sizeof(argv[0])*argc);
34 * opt_register_noarg("--help|--usage|-h", opt_usage_and_exit,
35 * "\nA oserver program", "Usage information");
36 * opt_register_arg("--port", opt_set_uintval, opt_show_uintval,
37 * &port, "Server port number");
38 * opt_register_noarg("--restore", opt_set_bool,
39 * &restore, opt_hidden);
41 * opt_parse(&argc, argv, opt_log_stderr_exit);
43 * opt_log_stderr_exit("Unknown extra arguments");
46 * if (!oserver_restore(ev, STATE_FILE))
47 * err(1, "Restoring server");
48 * } else if (!oserver_setup(ev, port, STATE_FILE, restore_argv))
49 * err(1, "Failed to set up server");
51 * while (tevent_loop_wait(ev) == 0);
52 * err(1, "Serving client");
55 int main(int argc, char *argv[])
57 /* Expect exactly one argument */
61 if (strcmp(argv[1], "depends") == 0) {
62 printf("ccan/read_write_all\n");
64 printf("ccan/foreach\n");
65 printf("ccan/failtest\n");
67 printf("ccan/array_size\n");
68 printf("ccan/tevent\n");
69 printf("ccan/cdump\n");
70 printf("ccan/grab_file\n");