Browse Source

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.
v0.7.4-release
Ryan 16 years ago
parent
commit
7aaab320b3
  1. 4
      src/http.js
  2. 6
      src/net.cc
  3. 4
      src/net.h
  4. 2
      test/mjsunit/test-http-server.js
  5. 2
      test/mjsunit/test-tcp-many-clients.js
  6. 8
      test/mjsunit/test-tcp-pingpong-delay.js
  7. 4
      test/mjsunit/test-tcp-pingpong.js
  8. 2
      test/mjsunit/test-tcp-raw.js
  9. 7
      test/mjsunit/test-tcp-reconnect.js
  10. 6
      website/api.txt

4
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") {

6
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<Value> argv[1];
argv[0] = stream_.errorno == 0 ? False() : True();
Emit("disconnect", 1, argv);
Emit("close", 1, argv);
}
#define DEFINE_SIMPLE_CALLBACK(name, type) \

4
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<v8::Object> 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));

2
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");
});
}

2
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);

8
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();

4
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();

2
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();
});

7
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)

6
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+::

Loading…
Cancel
Save