From f0a440d886bf5d7f84203c0520b274dbe834a5da Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Felix=20Geisendo=CC=88rfer?= Date: Sat, 14 May 2011 12:24:48 +0200 Subject: [PATCH] Remove 'connect' event from server side sockets Sockets emitted by the 'connection' event are always connected, having them emit the 'connect' event makes no sense. It only confused people, as it's not clear if you have to listen to 'connect' or not. That try..catch block was also very scary. It would silently swallow exceptions in 'connect' listeners and destroy the socket. Makes no sense. Fixes #1047. --- lib/net.js | 9 --------- test/simple/test-net-reconnect.js | 4 +--- 2 files changed, 1 insertion(+), 12 deletions(-) diff --git a/lib/net.js b/lib/net.js index 26acbb35588..826d69f4ae8 100644 --- a/lib/net.js +++ b/lib/net.js @@ -951,15 +951,6 @@ 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 8455f1689ed..a640cb9b134 100644 --- a/test/simple/test-net-reconnect.js +++ b/test/simple/test-net-reconnect.js @@ -30,9 +30,7 @@ var client_recv_count = 0; var disconnect_count = 0; var server = net.createServer(function(socket) { - socket.addListener('connect', function() { - socket.write('hello\r\n'); - }); + socket.write('hello\r\n'); socket.addListener('end', function() { socket.end();