summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorMax Romanov <max.romanov@nginx.com>2019-04-01 16:40:40 +0300
committerMax Romanov <max.romanov@nginx.com>2019-04-01 16:40:40 +0300
commit8557cb366092ea1bbc88386bdd79b9dad5867f19 (patch)
tree364b69ed01c22eee2fec69bcb06ab3a57ceef264
parentaca42de18ad9877db7e4a7f598a4c5cb55644fe8 (diff)
downloadunit-8557cb366092ea1bbc88386bdd79b9dad5867f19.tar.gz
unit-8557cb366092ea1bbc88386bdd79b9dad5867f19.tar.bz2
Introducing close event to notify about server stop.
This closes #236 on GitHub. Thanks to 0xcdcdcdcd.
-rwxr-xr-xsrc/nodejs/unit-http/http_server.js4
-rw-r--r--src/nodejs/unit-http/unit.cpp21
2 files changed, 25 insertions, 0 deletions
diff --git a/src/nodejs/unit-http/http_server.js b/src/nodejs/unit-http/http_server.js
index 057a1f26..0ac5d649 100755
--- a/src/nodejs/unit-http/http_server.js
+++ b/src/nodejs/unit-http/http_server.js
@@ -387,6 +387,10 @@ Server.prototype.emit_events = function (server, req, res) {
});
};
+Server.prototype.emit_close = function () {
+ this.emit('close');
+};
+
function connectionListener(socket) {
}
diff --git a/src/nodejs/unit-http/unit.cpp b/src/nodejs/unit-http/unit.cpp
index e4072851..e0cfaba3 100644
--- a/src/nodejs/unit-http/unit.cpp
+++ b/src/nodejs/unit-http/unit.cpp
@@ -313,6 +313,27 @@ Unit::remove_port(nxt_unit_ctx_t *ctx, nxt_unit_port_id_t *port_id)
void
Unit::quit(nxt_unit_ctx_t *ctx)
{
+ Unit *obj;
+ napi_value server_obj, emit_close;
+
+ obj = reinterpret_cast<Unit *>(ctx->unit->data);
+
+ try {
+ nxt_handle_scope scope(obj->env());
+
+ server_obj = obj->get_server_object();
+
+ emit_close = obj->get_named_property(server_obj, "emit_close");
+
+ nxt_async_context async_context(obj->env(), "unit_quit");
+ nxt_callback_scope async_scope(async_context);
+
+ obj->make_callback(async_context, server_obj, emit_close, 0, NULL);
+
+ } catch (exception &e) {
+ obj->throw_error(e);
+ }
+
nxt_unit_done(ctx);
}