From c53aeb5a0258ae8715d2644ba3a03dfe3fb32bcb Mon Sep 17 00:00:00 2001 From: Ryan Dahl Date: Wed, 23 Sep 2009 16:09:40 +0200 Subject: [PATCH] Call "connection" event after connection object is fully formed. This became an apparent problem when adding setNoDelay because the command was ignored if issued during the "connection" event. --- src/net.cc | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/src/net.cc b/src/net.cc index f86c28cb22..7e67cbe174 100644 --- a/src/net.cc +++ b/src/net.cc @@ -391,6 +391,18 @@ void Connection::OnClose() { Emit("close", 1, argv); } +void Connection::OnConnect() { + HandleScope scope; + + if (stream_.server) { + Server *server = static_cast(stream_.server->data); + Local value = Local::New(handle_); + server->Emit("connection", 1, &value); + } + + Emit("connect", 0, NULL); +} + #define DEFINE_SIMPLE_CALLBACK(name, type) \ void name() \ { \ @@ -398,7 +410,6 @@ void name() \ Emit(type, 0, NULL); \ } -DEFINE_SIMPLE_CALLBACK(Connection::OnConnect, "connect") DEFINE_SIMPLE_CALLBACK(Connection::OnTimeout, "timeout") DEFINE_SIMPLE_CALLBACK(Connection::OnEOF, "eof") @@ -469,10 +480,6 @@ Connection* Server::OnConnection(struct sockaddr *addr) { Connection *connection = UnwrapConnection(js_connection); if (!connection) return NULL; - Handle argv[1] = { js_connection }; - - Emit("connection", 1, argv); - connection->Attach(); return connection;