Browse Source

Add 'close' event to tcp.Server

v0.7.4-release
Ryan 15 years ago
parent
commit
f99fbc61e1
  1. 10
      src/net.cc
  2. 9
      src/net.h
  3. 9
      website/api.txt

10
src/net.cc

@ -558,6 +558,16 @@ Server::OnConnection (struct sockaddr *addr)
return connection;
}
void
Server::OnClose (int errorno)
{
HandleScope scope;
Handle<Value> argv[1] = { Integer::New(errorno) };
Emit("close", 1, argv);
}
// TODO Server->SetOptions
// TODO Server -> Server rename

9
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<v8::FunctionTemplate> 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<Server*> (s->data);
server->OnClose(errorno);
server->Detach();
}
evnet_server server_;
};

9
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={});+ ::

Loading…
Cancel
Save