diff options
| author | Oskari Timperi <oskari.timperi@iki.fi> | 2014-05-25 13:06:57 +0300 |
|---|---|---|
| committer | Oskari Timperi <oskari.timperi@iki.fi> | 2014-05-25 13:06:57 +0300 |
| commit | 0ae56484d334114120c59c0f4593c212b8bf2d08 (patch) | |
| tree | d0897beca625f3478abbb471450497ffa5ed1714 /examples/hello.c | |
| parent | 7cccad8512b5e2ea7fa37e7551135ff5a8165fab (diff) | |
| download | libuvh-0ae56484d334114120c59c0f4593c212b8bf2d08.tar.gz libuvh-0ae56484d334114120c59c0f4593c212b8bf2d08.zip | |
update example/hello.c to work
Diffstat (limited to 'examples/hello.c')
| -rw-r--r-- | examples/hello.c | 20 |
1 files changed, 17 insertions, 3 deletions
diff --git a/examples/hello.c b/examples/hello.c index 807a5ab..7f18f79 100644 --- a/examples/hello.c +++ b/examples/hello.c @@ -25,15 +25,23 @@ int request_handler(struct uvh_request *req) printf("request content length: %d\n", req->content_length); uvh_request_write_status(req, 418); - uvh_request_write_header(req, "Content-Length", "7"); uvh_request_write_header(req, "X-FOOBAR", "whee"); - uvh_request_write_header(req, "Connection", "close"); - uvh_request_write(req, "\r\nfoobar\n", 9); + uvh_request_write(req, "foobar\n", 7); + uvh_request_end(req); return 0; } +void ctrlc_handler(uv_signal_t *handle, int signum) +{ + struct uvh_server *server = handle->data; + uvh_server_stop(server); + uv_close((uv_handle_t *) handle, NULL); + (void) signum; +} + int main() { + uv_signal_t sig; struct uvh_server *server = uvh_server_init(uv_default_loop(), NULL, &request_handler); @@ -43,8 +51,14 @@ int main() if (uvh_server_listen(server, "127.0.0.1", 9898)) goto error; + uv_signal_init(uv_default_loop(), &sig); + sig.data = server; + uv_signal_start(&sig, &ctrlc_handler, SIGINT); + uv_run(uv_default_loop(), UV_RUN_DEFAULT); + printf("done\n"); + return 0; error: |
