]> git.ozlabs.org Git - ccan-lca-2011.git/blob - ccan/oserver/oserver.h
6b9a3e75c0ddce73d0d583ae28ab8af9b9694f59
[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  *
11  * Opens a socket and binds it to @port, then sets it up to listen
12  * for connections.  talloc_free() the pointer returned to shut it down
13  * (its parent is the tevent_context).
14  *
15  * Example:
16  *      struct oserver *oserver;
17  *      struct tevent_context *ev;
18  *
19  *      ev = tevent_context_init(NULL);
20  *      oserver = oserver_setup(ev, OSERVER_PORT);
21  *      if (!oserver)
22  *              err(1, "Failed to set up server");
23  *
24  *      while (tevent_loop_wait(ev) == 0);
25  *      err(1, "Event loop failed");
26  */
27 struct oserver *oserver_setup(struct tevent_context *ev, unsigned short port);
28
29 #define OSERVER_PORT 2727
30 #endif /* CCAN_OSERVER_H */