From f99fbc61e1e1e357e63a45e0e323cff34a98537c Mon Sep 17 00:00:00 2001 From: Ryan Date: Mon, 13 Jul 2009 15:36:14 +0200 Subject: [PATCH] Add 'close' event to tcp.Server --- src/net.cc | 10 ++++++++++ src/net.h | 9 ++++++++- website/api.txt | 9 +++++++++ 3 files changed, 27 insertions(+), 1 deletion(-) diff --git a/src/net.cc b/src/net.cc index c18e00fe81..24b8f60bcb 100644 --- a/src/net.cc +++ b/src/net.cc @@ -558,6 +558,16 @@ Server::OnConnection (struct sockaddr *addr) return connection; } +void +Server::OnClose (int errorno) +{ + HandleScope scope; + + Handle argv[1] = { Integer::New(errorno) }; + + Emit("close", 1, argv); +} + // TODO Server->SetOptions // TODO Server -> Server rename diff --git a/src/net.h b/src/net.h index 02e53a3644..34c9d17885 100644 --- a/src/net.h +++ b/src/net.h @@ -127,6 +127,7 @@ protected: { evnet_server_init(&server_); server_.on_connection = Server::on_connection; + server_.on_close = Server::on_close; server_.data = this; } @@ -144,7 +145,6 @@ protected: void Close ( ) { evnet_server_close (&server_); - Detach(); } virtual v8::Handle GetConnectionTemplate (void); @@ -158,6 +158,13 @@ private: return &connection->socket_; } + void OnClose (int errorno); + static void on_close (evnet_server *s, int errorno) { + Server *server = static_cast (s->data); + server->OnClose(errorno); + server->Detach(); + } + evnet_server server_; }; diff --git a/website/api.txt b/website/api.txt index f463e37ac0..db68b0701b 100644 --- a/website/api.txt +++ b/website/api.txt @@ -586,6 +586,11 @@ When a new TCP connection is established. want to access this event. The +connection+ can also be accessed at +request.connection+. +|+"close"+ | +errorno+ | Emitted when the server closes. +errorno+ + is an integer which indicates what, if any, + error caused the server to close. If no + error occured +errorno+ will be 0. + |========================================================= +node.http.createServer(request_listener, options);+ :: @@ -897,6 +902,10 @@ server.listen(7000, "localhost"); |Event | Parameters | Notes |+"connection"+ | +connection+ | Emitted when a new connection is made. +connection+ is an instance of +node.tcp.Connection+. +|+"close"+ | +errorno+ | Emitted when the server closes. +errorno+ + is an integer which indicates what, if any, + error caused the server to close. If no + error occured +errorno+ will be 0. |========================================================= +node.tcp.createServer(connection_listener, options={});+ ::