]> git.ozlabs.org Git - ccan-lca-2011.git/blob - ccan/oserver/oserver.h
3342ba83e61850def0eb60109c068b501b2312f8
[ccan-lca-2011.git] / ccan / oserver / oserver.h
1 #ifndef CCAN_OSERVER_H
2 #define CCAN_OSERVER_H
3 #include <stdbool.h>
4 #include <ccan/tevent/tevent.h>
5
6 /**
7  * oserver_setup - set up an oserver
8  * @ev: tevent context to use.
9  * @port: port to use (usually OSERVER_PORT)
10  * @dumpfile: file to save state to on SIGHUP (if non-NULL).
11  *
12  * Opens a socket and binds it to @port, then sets it up to listen
13  * for connections.  talloc_free() the pointer returned to shut it down
14  * (its parent is the tevent_context).
15  *
16  * Example:
17  *      struct oserver *oserver;
18  *      struct tevent_context *ev;
19  *
20  *      ev = tevent_context_init(NULL);
21  *      oserver = oserver_setup(ev, OSERVER_PORT, "oserver.dump");
22  *      if (!oserver)
23  *              err(1, "Failed to set up server");
24  *
25  *      while (tevent_loop_wait(ev) == 0);
26  *      err(1, "Event loop failed");
27  */
28 struct oserver *oserver_setup(struct tevent_context *ev, unsigned short port,
29                               const char *dumpfile);
30
31 #define OSERVER_PORT 2828
32 #endif /* CCAN_OSERVER_H */