* #include <sys/types.h>
* #include <sys/socket.h>
* #include <ccan/oserver/oserver.h>
+ * #include <ccan/opt/opt.h>
* #include <err.h>
* #include <stdlib.h>
*
- * int main(void)
+ * #define STATE_FILE "/var/run/oserver/dump"
+ *
+ * int main(int argc, char *argv[])
* {
- * int fd, sockfd;
+ * struct tevent_context *ev = tevent_context_init(NULL);
+ * unsigned int port = OSERVER_PORT;
+ * bool restore = false;
+ * char **restore_argv;
+ *
+ * // Save args before opt_parse mangles them.
+ * restore_argv = talloc_array(NULL, char *, argc+2);
+ * restore_argv[0] = argv[0];
+ * restore_argv[1] = "--restore";
+ * memcpy(restore_argv+2, argv+1, sizeof(argv[0])*argc);
+ *
+ * opt_register_noarg("--help|--usage|-h", opt_usage_and_exit,
+ * "\nA oserver program", "Usage information");
+ * opt_register_arg("--port", opt_set_uintval, opt_show_uintval,
+ * &port, "Server port number");
+ * opt_register_noarg("--restore", opt_set_bool,
+ * &restore, opt_hidden);
*
- * sockfd = oserver_setup();
+ * opt_parse(&argc, argv, opt_log_stderr_exit);
+ * if (argc != 1)
+ * opt_log_stderr_exit("Unknown extra arguments");
*
- * fd = accept(sockfd, NULL, NULL);
- * if (fd < 0)
- * err(1, "Accepting connection on TCP socket");
+ * if (restore) {
+ * if (!oserver_restore(ev, STATE_FILE))
+ * err(1, "Restoring server");
+ * } else if (!oserver_setup(ev, port, STATE_FILE, restore_argv))
+ * err(1, "Failed to set up server");
*
- * if (!oserver_serve(fd))
- * err(1, "Serving client");
- * exit(0);
+ * while (tevent_loop_wait(ev) == 0);
+ * err(1, "Serving client");
* }
*/
int main(int argc, char *argv[])
printf("ccan/read_write_all\n");
printf("ccan/str\n");
printf("ccan/foreach\n");
+ printf("ccan/failtest\n");
+ printf("ccan/opt\n");
+ printf("ccan/array_size\n");
+ printf("ccan/tevent\n");
+ printf("ccan/cdump\n");
+ printf("ccan/grab_file\n");
return 0;
}