From 7aaab320b30738494359e49537c0a7e00921425f Mon Sep 17 00:00:00 2001 From: Ryan Date: Fri, 14 Aug 2009 12:51:46 +0200 Subject: [PATCH] API: tcp.Connection "disconnect" event renamed to "close". More semantic, since the event will be emitted on connection error, when the connection was ever established. --- src/http.js | 4 ++-- src/net.cc | 6 +++--- src/net.h | 4 ++-- test/mjsunit/test-http-server.js | 2 +- test/mjsunit/test-tcp-many-clients.js | 2 +- test/mjsunit/test-tcp-pingpong-delay.js | 8 ++++---- test/mjsunit/test-tcp-pingpong.js | 4 ++-- test/mjsunit/test-tcp-raw.js | 2 +- test/mjsunit/test-tcp-reconnect.js | 7 ++++--- website/api.txt | 6 +++--- 10 files changed, 23 insertions(+), 22 deletions(-) diff --git a/src/http.js b/src/http.js index 568d0a75ec..773cdb2b71 100644 --- a/src/http.js +++ b/src/http.js @@ -431,13 +431,13 @@ node.http.createClient = function (port, host) { client.close(); }); - client.addListener("disconnect", function (had_error) { + client.addListener("close", function (had_error) { if (had_error) { client.emit("error"); return; } - //node.debug("HTTP CLIENT onDisconnect. readyState = " + client.readyState); + //node.debug("HTTP CLIENT onClose. readyState = " + client.readyState); // If there are more requests to handle, reconnect. if (requests.length > 0 && client.readyState != "opening") { diff --git a/src/net.cc b/src/net.cc index b4f1384341..8d5e98433c 100644 --- a/src/net.cc +++ b/src/net.cc @@ -267,7 +267,7 @@ Connection::AfterResolve (eio_req *req) */ connection->stream_.errorno = req->result; - connection->OnDisconnect(); + connection->OnClose(); connection->Detach(); @@ -456,14 +456,14 @@ Connection::OnReceive (const void *buf, size_t len) } void -Connection::OnDisconnect () +Connection::OnClose () { HandleScope scope; Handle argv[1]; argv[0] = stream_.errorno == 0 ? False() : True(); - Emit("disconnect", 1, argv); + Emit("close", 1, argv); } #define DEFINE_SIMPLE_CALLBACK(name, type) \ diff --git a/src/net.h b/src/net.h index 65fd08236e..f71faa368f 100644 --- a/src/net.h +++ b/src/net.h @@ -57,7 +57,7 @@ protected: virtual void OnConnect (void); virtual void OnReceive (const void *buf, size_t len); virtual void OnEOF (void); - virtual void OnDisconnect (void); + virtual void OnClose (void); virtual void OnTimeout (void); v8::Local GetProtocol (void); @@ -94,7 +94,7 @@ private: assert(connection->stream_.fd < 0); - connection->OnDisconnect(); + connection->OnClose(); if (s->errorno) { printf("socket died: %s\n", strerror(s->errorno)); diff --git a/test/mjsunit/test-http-server.js b/test/mjsunit/test-http-server.js index fa726e29a4..3f84bab40d 100644 --- a/test/mjsunit/test-http-server.js +++ b/test/mjsunit/test-http-server.js @@ -57,7 +57,7 @@ function onLoad() { client_got_eof = true; }); - c.addListener("disconnect", function () { + c.addListener("close", function () { assertEquals(c.readyState, "closed"); }); } diff --git a/test/mjsunit/test-tcp-many-clients.js b/test/mjsunit/test-tcp-many-clients.js index 8c70cab241..1231562d19 100644 --- a/test/mjsunit/test-tcp-many-clients.js +++ b/test/mjsunit/test-tcp-many-clients.js @@ -41,7 +41,7 @@ function runClient (callback) { client.close(); }); - client.addListener("disconnect", function (had_error) { + client.addListener("close", function (had_error) { print("."); assertFalse(had_error); assertEquals(bytes, client.recved.length); diff --git a/test/mjsunit/test-tcp-pingpong-delay.js b/test/mjsunit/test-tcp-pingpong-delay.js index 07624d15df..8b8d6cf5d6 100644 --- a/test/mjsunit/test-tcp-pingpong-delay.js +++ b/test/mjsunit/test-tcp-pingpong-delay.js @@ -34,8 +34,8 @@ function pingPongTest (port, host, on_complete) { socket.close(); }); - socket.addListener("disconnect", function (had_error) { - puts("server-side socket disconnect"); + socket.addListener("close", function (had_error) { + puts("server-side socket close"); assertFalse(had_error); assertEquals("closed", socket.readyState); socket.server.close(); @@ -74,8 +74,8 @@ function pingPongTest (port, host, on_complete) { assertFalse(true); }); - client.addListener("disconnect", function () { - puts("client disconnect"); + client.addListener("close", function () { + puts("client close"); assertEquals(N+1, count); assertTrue(client_closed); if (on_complete) on_complete(); diff --git a/test/mjsunit/test-tcp-pingpong.js b/test/mjsunit/test-tcp-pingpong.js index eea45c276c..448f05d438 100644 --- a/test/mjsunit/test-tcp-pingpong.js +++ b/test/mjsunit/test-tcp-pingpong.js @@ -32,7 +32,7 @@ function pingPongTest (port, host, on_complete) { socket.close(); }); - socket.addListener("disconnect", function (had_error) { + socket.addListener("close", function (had_error) { assertFalse(had_error); assertEquals("closed", socket.readyState); socket.server.close(); @@ -69,7 +69,7 @@ function pingPongTest (port, host, on_complete) { } }); - client.addListener("disconnect", function () { + client.addListener("close", function () { assertEquals(N+1, count); assertTrue(sent_final_ping); if (on_complete) on_complete(); diff --git a/test/mjsunit/test-tcp-raw.js b/test/mjsunit/test-tcp-raw.js index 0acfc8e180..6dc73cd990 100644 --- a/test/mjsunit/test-tcp-raw.js +++ b/test/mjsunit/test-tcp-raw.js @@ -32,7 +32,7 @@ function onLoad () { c.send([j], "raw"); }); - c.addListener("disconnect", function () { + c.addListener("close", function () { p(recv); echoServer.close(); }); diff --git a/test/mjsunit/test-tcp-reconnect.js b/test/mjsunit/test-tcp-reconnect.js index b2ba3d4ac9..292e5fd25a 100644 --- a/test/mjsunit/test-tcp-reconnect.js +++ b/test/mjsunit/test-tcp-reconnect.js @@ -2,8 +2,9 @@ include("mjsunit.js"); var N = 50; var port = 8921; -var disconnect_count = 0; +var c = 0; var client_recv_count = 0; +var disconnect_count = 0; function onLoad () { @@ -16,7 +17,7 @@ function onLoad () { socket.close(); }); - socket.addListener("disconnect", function (had_error) { + socket.addListener("close", function (had_error) { //puts("server had_error: " + JSON.stringify(had_error)); assertFalse(had_error); }); @@ -38,7 +39,7 @@ function onLoad () { client.fullClose(); }); - client.addListener("disconnect", function (had_error) { + client.addListener("close", function (had_error) { puts("disconnect"); assertFalse(had_error); if (disconnect_count++ < N) diff --git a/website/api.txt b/website/api.txt index a305efd79f..d747f41cdb 100644 --- a/website/api.txt +++ b/website/api.txt @@ -997,8 +997,8 @@ socket for +node.tcp.Server+. will be +"writeOnly"+. One should probably just call +connection.close()+ when this event is emitted. -|+"disconnect"+ | +had_error+ | Emitted once the connection is fully - disconnected. The argument +had_error+ +|+"close"+ | +had_error+ | Emitted once the connection is fully + closed. The argument +had_error+ is a boolean which says if the connection was closed due to a transmission error. (TODO: access error codes.) @@ -1018,7 +1018,7 @@ another server. + This function is asynchronous. When the +"connect"+ event is emitted the connection is established. If there is a problem connecting, the +"connect"+ -event will not be emitted, the +"disconnect"+ event will be emitted with +event will not be emitted, the +"close"+ event will be emitted with +had_error == true+. +connection.remoteAddress+::