diff options
| author | Oskari Timperi <oskari.timperi@iki.fi> | 2014-05-25 13:05:33 +0300 |
|---|---|---|
| committer | Oskari Timperi <oskari.timperi@iki.fi> | 2014-05-25 13:05:33 +0300 |
| commit | 30fdee63b08c10e61343d226e135fd5690174b18 (patch) | |
| tree | bc7924c0f6496377402b33053566df919808a268 | |
| parent | 8af69e5e4065612d1f011ad497b837d779e5f67f (diff) | |
| download | libuvh-30fdee63b08c10e61343d226e135fd5690174b18.tar.gz libuvh-30fdee63b08c10e61343d226e135fd5690174b18.zip | |
add uvh_server_stop()
| -rw-r--r-- | src/uvh.c | 27 | ||||
| -rw-r--r-- | src/uvh.h | 2 |
2 files changed, 29 insertions, 0 deletions
@@ -64,6 +64,7 @@ struct uvh_server_private uv_loop_t *loop; struct http_parser_settings http_parser_settings; uv_tcp_t stream; + char stop; }; struct uvh_request_private @@ -144,6 +145,22 @@ int uvh_server_listen(struct uvh_server *server, const char *address, return 0; } +static void on_server_close(uv_handle_t *handle) +{ + LOG_DEBUG("%s", __FUNCTION__); +} + +void uvh_server_stop(struct uvh_server *server) +{ + struct uvh_server_private *p; + + p = container_of(server, struct uvh_server_private, server); + + p->stop = 1; + + uv_close((uv_handle_t *) &p->stream, &on_server_close); +} + static void on_connection(uv_stream_t *stream, int status) { struct uvh_server_private *priv = container_of((uv_tcp_t *) stream, @@ -157,6 +174,16 @@ static void on_connection(uv_stream_t *stream, int status) return; } + if (priv->stop) + { + LOG_WARNING("on_connection: stop bit set"); + uv_tcp_t *client = calloc(1, sizeof(*client)); + uv_tcp_init(priv->loop, client); + uv_accept(stream, (uv_stream_t *) client); + uv_close((uv_handle_t *) client, NULL); + return; + } + struct uvh_request_private *req = calloc(1, sizeof(*req)); req->req.server = &priv->server; req->header_state = 0; @@ -106,6 +106,8 @@ struct uvh_server *uvh_server_init(uv_loop_t *loop, void *data, int uvh_server_listen(struct uvh_server *server, const char *address, short port); +void uvh_server_stop(struct uvh_server *server); + void uvh_request_write(struct uvh_request *req, const char *data, size_t len); |
