aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/uvh.c27
-rw-r--r--src/uvh.h2
2 files changed, 29 insertions, 0 deletions
diff --git a/src/uvh.c b/src/uvh.c
index c27cff2..04fa1dc 100644
--- a/src/uvh.c
+++ b/src/uvh.c
@@ -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;
diff --git a/src/uvh.h b/src/uvh.h
index 525b6a8..76754a8 100644
--- a/src/uvh.h
+++ b/src/uvh.h
@@ -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);