]> git.ozlabs.org Git - ccan-lca-2011.git/commitdiff
lca2011: header documentation.
authorRusty Russell <rusty@rustcorp.com.au>
Fri, 21 Jan 2011 03:40:03 +0000 (14:10 +1030)
committerRusty Russell <rusty@rustcorp.com.au>
Fri, 21 Jan 2011 03:40:03 +0000 (14:10 +1030)
Particularly, the example sections (compile-tested thanks to ccanlint).

ccan/oserver/oserver.h

index fa214b4c951db53f78a8d0ecba418e03a3b02856..bf2b0ead5b7c362f09f2688ea89ab82bb492fb14 100644 (file)
@@ -2,8 +2,42 @@
 #define CCAN_OSERVER_H
 #include <ccan/compiler/compiler.h>
 
-void NORETURN oserver_serve(int fd);
+/**
+ * oserver_setup - get a listening filedescriptor for an oserver
+ *
+ * Opens a socket and binds it to OSERVER_PORT, then sets it up to listen
+ * for connections and returns it.
+ *
+ * Example:
+ *     int serverfd;
+ *
+ *     serverfd = oserver_setup();
+ *     if (serverfd < 0)
+ *             err(1, "Failed to set up server");
+ */
 int oserver_setup(void);
 
+/**
+ * oserver_serve - serve an oserver client via a file descriptor
+ * @fd: the file descriptor (usually a connected socket)
+ *
+ * This does not return, but exits with status 0 if served OK.
+ *
+ * Example:
+ *      #include <sys/types.h>
+ *      #include <sys/socket.h>
+ *     ...
+ *             int clientfd;
+ *     ...
+ *             clientfd = accept(serverfd, NULL, NULL);
+ *             if (clientfd < 0)
+ *                     err(1, "Accepting connection from client");
+ *             if (fork() == 0)
+ *                     oserver_serve(clientfd);
+ *             else
+ *                     close(clientfd);
+ */
+void NORETURN oserver_serve(int fd);
+
 #define OSERVER_PORT 2727
 #endif /* CCAN_OSERVER_H */