]> git.ozlabs.org Git - ccan-lca-2011.git/blobdiff - ccan/oserver/oserver.h
lca2011: don't use void * for the handle.
[ccan-lca-2011.git] / ccan / oserver / oserver.h
index d727560cd76455d092acd3db9a6e06adbd16add7..6b9a3e75c0ddce73d0d583ae28ab8af9b9694f59 100644 (file)
@@ -1,43 +1,30 @@
 #ifndef CCAN_OSERVER_H
 #define CCAN_OSERVER_H
 #include <stdbool.h>
+#include <ccan/tevent/tevent.h>
 
 /**
- * oserver_setup - get a listening filedescriptor for an oserver
+ * oserver_setup - set up an oserver
+ * @ev: tevent context to use.
+ * @port: port to use (usually OSERVER_PORT)
  *
- * Opens a socket and binds it to OSERVER_PORT, then sets it up to listen
- * for connections and returns it.
+ * Opens a socket and binds it to @port, then sets it up to listen
+ * for connections.  talloc_free() the pointer returned to shut it down
+ * (its parent is the tevent_context).
  *
  * Example:
- *     int serverfd;
+ *     struct oserver *oserver;
+ *     struct tevent_context *ev;
  *
- *     serverfd = oserver_setup();
- *     if (serverfd < 0)
+ *     ev = tevent_context_init(NULL);
+ *     oserver = oserver_setup(ev, OSERVER_PORT);
+ *     if (!oserver)
  *             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 returns false (with errno set) on failure.
- *
- * 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)
- *                     exit(oserver_serve(clientfd) ? 0 : 1);
- *             else
- *                     close(clientfd);
+ *     while (tevent_loop_wait(ev) == 0);
+ *     err(1, "Event loop failed");
  */
-bool oserver_serve(int fd);
+struct oserver *oserver_setup(struct tevent_context *ev, unsigned short port);
 
 #define OSERVER_PORT 2727
 #endif /* CCAN_OSERVER_H */