diff options
author | Sergey Poznyakoff <gray@nxc.no> | 2017-08-17 14:18:56 +0300 |
---|---|---|
committer | Sergey Poznyakoff <gray@nxc.no> | 2017-08-17 15:22:27 +0300 |
commit | f25c77a5f9af8e0c4eb40dfae1683f383104ed3a (patch) | |
tree | a727e78cbfb21c617d73b327262bcae645504466 /src/nssync.h | |
parent | 168d61f49a4ec1dc2a956e848000d970dffa017f (diff) | |
download | nssync-f25c77a5f9af8e0c4eb40dfae1683f383104ed3a.tar.gz nssync-f25c77a5f9af8e0c4eb40dfae1683f383104ed3a.tar.bz2 |
Implement asynchronous and periodic request handling in server mode.
In server mode, the server wakes up periodically to run synchronizations.
The wake up interval is configured by the server.wakeup statement.
By default, POST requests to /nssync endpoint are delayed for certain
time. This avoids spurious wake-ups if several requests come one
after another during a short time. The delay is configured by the
server.quarantine statement.
Finally, the GET request returns the latest wakeup status.
* src/Makefile.am [COND_MICROHTTPD] (PTHREAD_L): Add -lrt
[COND_MICROHTTPD] (nssync_SOURCES): Add timer.c
* src/config.c (server_kw): New keywords: "wakeup" and "delay".
* src/nssync.c (periodic_timeout)
(delay_timeout): New globals.
(nssync): Add timestamp to the response.
* src/nssync.h (periodic_timeout)
(delay_timeout): New externs.
(nssync_reschedule,nssync_timer):
(nssync_format_result): New protos.
* src/server.c (do_sync): Parse POST body. If present, it must
be a valid JSON object.
Handle GET requests (return most recent status).
(nssync_server): Start nssync_timer thread.
* src/timer.c: New file.
* NEWS: Update.
* doc/nssync.texi: Update.
* doc/nssync.8: Update.
Diffstat (limited to 'src/nssync.h')
-rw-r--r-- | src/nssync.h | 7 |
1 files changed, 7 insertions, 0 deletions
diff --git a/src/nssync.h b/src/nssync.h index 27baf23..e8150ac 100644 --- a/src/nssync.h +++ b/src/nssync.h @@ -51,6 +51,8 @@ extern struct grecs_sockaddr *server_addr; #ifndef DEFAULT_NSSYNC_ADDR # define DEFAULT_NSSYNC_ADDR "127.0.0.1:8080" #endif +extern unsigned periodic_timeout; +extern unsigned delay_timeout; extern char *sql_config_file; extern char *sql_config_group; @@ -151,7 +153,12 @@ int move_file(const char *file, const char *dst_file); int copy_file(const char *file_name, FILE *infile, const char *dst_file); void filetab_clear(void); + int nssync_server(void); +void nssync_reschedule(int); +void *nssync_timer(void *arg); +char *nssync_format_result(void); + int nssync(struct json_value **ret_json); |