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.
This commit is contained in:
Ryan 2009-08-14 12:51:46 +02:00
Родитель 95f9209966
Коммит 7aaab320b3
10 изменённых файлов: 23 добавлений и 22 удалений

Просмотреть файл

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

Просмотреть файл

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

Просмотреть файл

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

Просмотреть файл

@ -57,7 +57,7 @@ function onLoad() {
client_got_eof = true;
});
c.addListener("disconnect", function () {
c.addListener("close", function () {
assertEquals(c.readyState, "closed");
});
}

Просмотреть файл

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

Просмотреть файл

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

Просмотреть файл

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

Просмотреть файл

@ -32,7 +32,7 @@ function onLoad () {
c.send([j], "raw");
});
c.addListener("disconnect", function () {
c.addListener("close", function () {
p(recv);
echoServer.close();
});

Просмотреть файл

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

Просмотреть файл

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