#include <stdlib.h>
#include <stdio.h>
#include <time.h>
#include <err.h>
#include <event2/event.h>
#include <event2/http.h>
#include <event2/buffer.h>
void now_handler(struct evhttp_request *req, void *arg) {
struct evbuffer *buf = evhttp_request_get_output_buffer(req);
evbuffer_add_printf(buf, "{\"now\":%d}", (int) time(NULL));
evhttp_send_reply(req, HTTP_OK, "OK", NULL);
}
int main(int argc, char **argv) {
struct evhttp *httpd;
struct event_base *base = event_base_new();
httpd = evhttp_new(base);
evhttp_bind_socket(httpd, "0.0.0.0", 8980);
evhttp_set_gencb(httpd, now_handler, NULL);
event_base_dispatch(base);
/* Not reached in this code as it is now. */
evhttp_free(httpd);
return 0;
}