From ede1acc1ed6c5badd53226c4798afa23186ab12a Mon Sep 17 00:00:00 2001 From: Ryan Dahl Date: Tue, 5 Jul 2011 10:52:22 -0700 Subject: [PATCH] Revert "Remove 'connect' event from server side sockets" Fixes #1276 This reverts commit f0a440d886bf5d7f84203c0520b274dbe834a5da. --- lib/net_legacy.js | 9 +++++++++ test/simple/test-net-reconnect.js | 4 +++- 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/lib/net_legacy.js b/lib/net_legacy.js index 52f4e9405b5..b2b997718b1 100644 --- a/lib/net_legacy.js +++ b/lib/net_legacy.js @@ -955,6 +955,15 @@ function Server(/* [ options, ] listener */) { DTRACE_NET_SERVER_CONNECTION(s); self.emit('connection', s); + + // The 'connect' event probably should be removed for server-side + // sockets. It's redundant. + try { + s.emit('connect'); + } catch (e) { + s.destroy(e); + return; + } } }; } diff --git a/test/simple/test-net-reconnect.js b/test/simple/test-net-reconnect.js index a640cb9b134..8455f1689ed 100644 --- a/test/simple/test-net-reconnect.js +++ b/test/simple/test-net-reconnect.js @@ -30,7 +30,9 @@ var client_recv_count = 0; var disconnect_count = 0; var server = net.createServer(function(socket) { - socket.write('hello\r\n'); + socket.addListener('connect', function() { + socket.write('hello\r\n'); + }); socket.addListener('end', function() { socket.end();