]> git.ozlabs.org Git - ccan-lca-2011.git/blob - ccan/oserver/oserver.h
lca2011: dump, re-exec with --restore on restart.
[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_restore - restore an oserver from dump
8  * @ev: tevent context to use.
9  * @dumpfile: file to with saved state.
10  *
11  * Tries to restore an oserver from the dump file.  Returns NULL on failure.
12  * 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_restore(ev, "oserver.dump");
21  *      if (oserver)
22  *              printf("Restored oserver!");
23  */
24 struct oserver *oserver_restore(struct tevent_context *ev,
25                                 const char *dumpfile);
26
27
28 /**
29  * oserver_setup - set up an oserver
30  * @ev: tevent context to use.
31  * @port: port to use (usually OSERVER_PORT)
32  * @dumpfile: file to save state to on SIGHUP (if non-NULL).
33  * @argv: arguments to re-exec on SIGHUP (if non-NULL).
34  *
35  * Opens a socket and binds it to @port, then sets it up to listen
36  * for connections.  talloc_free() the pointer returned to shut it down
37  * (its parent is the tevent_context).
38  *
39  * Example:
40  *      ...
41  *      else {
42  *              oserver = oserver_setup(ev, OSERVER_PORT, "oserver.dump", argv);
43  *              if (!oserver)
44  *                      err(1, "Failed to set up server");
45  *      }
46  *      while (tevent_loop_wait(ev) == 0);
47  *      err(1, "Event loop failed");
48  */
49 struct oserver *oserver_setup(struct tevent_context *ev, unsigned short port,
50                               const char *dumpfile, char *argv[]);
51
52 #define OSERVER_PORT 2828
53 #endif /* CCAN_OSERVER_H */