From bc17d94a0a5d1e8d2b432c424b7def6556fc1abe Mon Sep 17 00:00:00 2001 From: Ryan Dahl Date: Fri, 12 Feb 2010 00:25:15 -0800 Subject: [PATCH] API: tcp events 'receive' to 'data', 'eof' to 'end' No deprecation messages. Not sure how... --- doc/api.txt | 12 ++++++------ lib/http.js | 6 +++--- src/node_http.cc | 6 +++--- src/node_net.cc | 12 ++++++------ test/mjsunit/test-http-1.0.js | 4 ++-- test/mjsunit/test-http-client-reconnect-bug.js | 2 +- test/mjsunit/test-http-server.js | 4 ++-- test/mjsunit/test-http-wget.js | 6 +++--- test/mjsunit/test-stdio.js | 2 +- test/mjsunit/test-tcp-binary.js | 6 +++--- test/mjsunit/test-tcp-many-clients.js | 4 ++-- test/mjsunit/test-tcp-pingpong-delay.js | 6 +++--- test/mjsunit/test-tcp-pingpong.js | 6 +++--- test/mjsunit/test-tcp-reconnect.js | 4 ++-- test/mjsunit/test-tcp-throttle-kernel-buffer.js | 4 ++-- test/mjsunit/test-tcp-throttle.js | 4 ++-- test/mjsunit/test-tcp-timeout.js | 10 +++++----- test/mjsunit/test-tcp-tls.js | 6 +++--- 18 files changed, 52 insertions(+), 52 deletions(-) diff --git a/doc/api.txt b/doc/api.txt index 87af8b0f6e..4cd0d95cea 100644 --- a/doc/api.txt +++ b/doc/api.txt @@ -234,7 +234,7 @@ there is a connection, a child process emits an event when it exits. All objects which emit events are instances of +events.EventEmitter+. Events are represented by a camel-cased string. Here are some examples: -+"connection"+, +"receive"+, +"messageBegin"+. ++"connection"+, +"data"+, +"messageBegin"+. Functions can be then be attached to objects, to be executed when an event is emitted. These functions are called _listeners_. @@ -1353,10 +1353,10 @@ var server = tcp.createServer(function (socket) { socket.addListener("connect", function () { socket.send("hello\r\n"); }); - socket.addListener("receive", function (data) { + socket.addListener("data", function (data) { socket.send(data); }); - socket.addListener("eof", function () { + socket.addListener("end", function () { socket.send("goodbye\r\n"); socket.close(); }); @@ -1421,11 +1421,11 @@ socket for +tcp.Server+. |+"connect"+ | | Call once the connection is established after a call to +createConnection()+ or +connect()+. -|+"receive"+ | +data+ | Called when data is received on the +|+"data"+ | +data+ | Called when data is received on the connection. +data+ will be a string. Encoding of data is set by +connection.setEncoding()+. -|+"eof"+ | | Called when the other end of the +|+"end"+ | | Called when the other end of the connection sends a FIN packet. After this is emitted the +readyState+ will be +"writeOnly"+. One should probably @@ -1491,7 +1491,7 @@ Ensures that no more I/O activity happens on this socket. Only necessary in case of errors (parse error or so). +connection.readPause()+:: -Pauses the reading of data. That is, +"receive"+ events will not be emitted. +Pauses the reading of data. That is, +"data"+ events will not be emitted. Useful to throttle back an upload. +connection.readResume()+:: diff --git a/lib/http.js b/lib/http.js index dcb152e987..d455506f28 100644 --- a/lib/http.js +++ b/lib/http.js @@ -387,7 +387,7 @@ function connectionListener (connection) { connection.resetParser(); // is this really needed? - connection.addListener("eof", function () { + connection.addListener("end", function () { if (responses.length == 0) { connection.close(); } else { @@ -456,8 +456,8 @@ exports.createClient = function (port, host) { currentRequest.flush(); }); - client.addListener("eof", function () { - //sys.debug("client got eof closing. readyState = " + client.readyState); + client.addListener("end", function () { + //sys.debug("client got end closing. readyState = " + client.readyState); client.close(); }); diff --git a/src/node_http.cc b/src/node_http.cc index 9794b90567..4f49967322 100644 --- a/src/node_http.cc +++ b/src/node_http.cc @@ -27,7 +27,7 @@ static Persistent header_field_symbol; static Persistent header_value_symbol; static Persistent header_complete_symbol; static Persistent body_symbol; -static Persistent eof_symbol; +static Persistent end_symbol; static Persistent delete_sym; static Persistent get_sym; @@ -66,7 +66,7 @@ HTTPConnection::Initialize (Handle target) NODE_SET_PROTOTYPE_METHOD(server_constructor_template, "resetParser", ResetParser); server_constructor_template->SetClassName(String::NewSymbol("ServerSideConnection")); - eof_symbol = NODE_PSYMBOL("eof"); + end_symbol = NODE_PSYMBOL("end"); } @@ -123,7 +123,7 @@ HTTPConnection::OnEOF () assert(refs_); size_t nparsed; nparsed = http_parser_execute(&parser_, NULL, 0); - Emit(eof_symbol, 0, NULL); + Emit(end_symbol, 0, NULL); } int diff --git a/src/node_net.cc b/src/node_net.cc index dad2906d64..4704c73093 100644 --- a/src/node_net.cc +++ b/src/node_net.cc @@ -32,12 +32,12 @@ static Persistent write_only_symbol; static Persistent closing_symbol; static Persistent closed_symbol; -static Persistent receive_symbol; +static Persistent data_symbol; static Persistent connection_symbol; static Persistent connect_symbol; static Persistent timeout_symbol; static Persistent drain_symbol; -static Persistent eof_symbol; +static Persistent end_symbol; static Persistent close_symbol; static const struct addrinfo server_tcp_hints = @@ -76,12 +76,12 @@ void Connection::Initialize(v8::Handle target) { closing_symbol = NODE_PSYMBOL("closing"); closed_symbol = NODE_PSYMBOL("closed"); - receive_symbol = NODE_PSYMBOL("receive"); + data_symbol = NODE_PSYMBOL("data"); connection_symbol = NODE_PSYMBOL("connection"); connect_symbol = NODE_PSYMBOL("connect"); timeout_symbol = NODE_PSYMBOL("timeout"); drain_symbol = NODE_PSYMBOL("drain"); - eof_symbol = NODE_PSYMBOL("eof"); + end_symbol = NODE_PSYMBOL("end"); close_symbol = NODE_PSYMBOL("close"); Local t = FunctionTemplate::New(New); @@ -618,7 +618,7 @@ Handle Connection::Send(const Arguments& args) { void Connection::OnReceive(const void *buf, size_t len) { HandleScope scope; Local data = Encode(buf, len, encoding_); - Emit(receive_symbol, 1, &data); + Emit(data_symbol, 1, &data); } void Connection::OnClose() { @@ -656,7 +656,7 @@ void Connection::OnDrain() { void Connection::OnEOF() { HandleScope scope; - Emit(eof_symbol, 0, NULL); + Emit(end_symbol, 0, NULL); } Persistent Server::constructor_template; diff --git a/test/mjsunit/test-http-1.0.js b/test/mjsunit/test-http-1.0.js index ffc69e0808..9fc0a5d0ae 100644 --- a/test/mjsunit/test-http-1.0.js +++ b/test/mjsunit/test-http-1.0.js @@ -23,12 +23,12 @@ c.addListener("connect", function () { c.send( "GET / HTTP/1.0\r\n\r\n" ); }); -c.addListener("receive", function (chunk) { +c.addListener("data", function (chunk) { puts(chunk); server_response += chunk; }); -c.addListener("eof", function () { +c.addListener("end", function () { client_got_eof = true; c.close(); server.close(); diff --git a/test/mjsunit/test-http-client-reconnect-bug.js b/test/mjsunit/test-http-client-reconnect-bug.js index 16a63f99ba..c8d2999434 100644 --- a/test/mjsunit/test-http-client-reconnect-bug.js +++ b/test/mjsunit/test-http-client-reconnect-bug.js @@ -21,7 +21,7 @@ client.addListener("error", function() { errorCount++; }); -client.addListener("eof", function() { +client.addListener("end", function() { sys.puts("EOF!"); eofCount++; }); diff --git a/test/mjsunit/test-http-server.js b/test/mjsunit/test-http-server.js index 63e394b4c9..35b05f2409 100644 --- a/test/mjsunit/test-http-server.js +++ b/test/mjsunit/test-http-server.js @@ -54,7 +54,7 @@ c.addListener("connect", function () { requests_sent += 1; }); -c.addListener("receive", function (chunk) { +c.addListener("data", function (chunk) { server_response += chunk; if (requests_sent == 1) { @@ -72,7 +72,7 @@ c.addListener("receive", function (chunk) { }); -c.addListener("eof", function () { +c.addListener("end", function () { client_got_eof = true; }); diff --git a/test/mjsunit/test-http-wget.js b/test/mjsunit/test-http-wget.js index 3073c1ddd6..33c477f452 100644 --- a/test/mjsunit/test-http-wget.js +++ b/test/mjsunit/test-http-wget.js @@ -40,14 +40,14 @@ c.addListener("connect", function () { "Connection: Keep-Alive\r\n\r\n"); }); -c.addListener("receive", function (chunk) { +c.addListener("data", function (chunk) { puts(chunk); server_response += chunk; }); -c.addListener("eof", function () { +c.addListener("end", function () { client_got_eof = true; - puts('got eof'); + puts('got end'); c.close(); }); diff --git a/test/mjsunit/test-stdio.js b/test/mjsunit/test-stdio.js index e8bc6842d0..786e9e187a 100644 --- a/test/mjsunit/test-stdio.js +++ b/test/mjsunit/test-stdio.js @@ -24,7 +24,7 @@ child.addListener("output", function (data){ child.close(); } } else { - puts('child eof'); + puts('child end'); } }); diff --git a/test/mjsunit/test-tcp-binary.js b/test/mjsunit/test-tcp-binary.js index b91f2a6bce..5ce6b9af84 100644 --- a/test/mjsunit/test-tcp-binary.js +++ b/test/mjsunit/test-tcp-binary.js @@ -21,11 +21,11 @@ for (var i = 255; i >= 0; i--) { var echoServer = tcp.createServer(function (connection) { connection.setEncoding("binary"); - connection.addListener("receive", function (chunk) { + connection.addListener("data", function (chunk) { error("recved: " + JSON.stringify(chunk)); connection.send(chunk, "binary"); }); - connection.addListener("eof", function () { + connection.addListener("end", function () { connection.close(); }); }); @@ -37,7 +37,7 @@ var j = 0; var c = tcp.createConnection(PORT); c.setEncoding("binary"); -c.addListener("receive", function (chunk) { +c.addListener("data", function (chunk) { if (j < 256) { error("send " + j); c.send(String.fromCharCode(j), "binary"); diff --git a/test/mjsunit/test-tcp-many-clients.js b/test/mjsunit/test-tcp-many-clients.js index 0dfda16113..69fb1459f9 100644 --- a/test/mjsunit/test-tcp-many-clients.js +++ b/test/mjsunit/test-tcp-many-clients.js @@ -35,11 +35,11 @@ function runClient (callback) { client.connections += 1; }); - client.addListener("receive", function (chunk) { + client.addListener("data", function (chunk) { this.recved += chunk; }); - client.addListener("eof", function (had_error) { + client.addListener("end", function (had_error) { client.close(); }); diff --git a/test/mjsunit/test-tcp-pingpong-delay.js b/test/mjsunit/test-tcp-pingpong-delay.js index 726ca7d8e8..d7d2bebcdb 100644 --- a/test/mjsunit/test-tcp-pingpong-delay.js +++ b/test/mjsunit/test-tcp-pingpong-delay.js @@ -13,7 +13,7 @@ function pingPongTest (port, host, on_complete) { var server = tcp.createServer(function (socket) { socket.setEncoding("utf8"); - socket.addListener("receive", function (data) { + socket.addListener("data", function (data) { puts(data); assert.equal("PING", data); assert.equal("open", socket.readyState); @@ -29,7 +29,7 @@ function pingPongTest (port, host, on_complete) { assert.equal(false, true); }); - socket.addListener("eof", function () { + socket.addListener("end", function () { puts("server-side socket EOF"); assert.equal("writeOnly", socket.readyState); socket.close(); @@ -53,7 +53,7 @@ function pingPongTest (port, host, on_complete) { client.send("PING"); }); - client.addListener("receive", function (data) { + client.addListener("data", function (data) { puts(data); assert.equal("PONG", data); assert.equal("open", client.readyState); diff --git a/test/mjsunit/test-tcp-pingpong.js b/test/mjsunit/test-tcp-pingpong.js index 89d53295ec..543fcfe49b 100644 --- a/test/mjsunit/test-tcp-pingpong.js +++ b/test/mjsunit/test-tcp-pingpong.js @@ -21,7 +21,7 @@ function pingPongTest (port, host, on_complete) { socket.setNoDelay(); socket.timeout = 0; - socket.addListener("receive", function (data) { + socket.addListener("data", function (data) { puts("server got: " + JSON.stringify(data)); assert.equal("open", socket.readyState); assert.equal(true, count <= N); @@ -30,7 +30,7 @@ function pingPongTest (port, host, on_complete) { } }); - socket.addListener("eof", function () { + socket.addListener("end", function () { assert.equal("writeOnly", socket.readyState); socket.close(); }); @@ -52,7 +52,7 @@ function pingPongTest (port, host, on_complete) { client.send("PING"); }); - client.addListener("receive", function (data) { + client.addListener("data", function (data) { assert.equal("PONG", data); count += 1; diff --git a/test/mjsunit/test-tcp-reconnect.js b/test/mjsunit/test-tcp-reconnect.js index 483283846e..6d2a125f92 100644 --- a/test/mjsunit/test-tcp-reconnect.js +++ b/test/mjsunit/test-tcp-reconnect.js @@ -12,7 +12,7 @@ var server = tcp.createServer(function (socket) { socket.send("hello\r\n"); }); - socket.addListener("eof", function () { + socket.addListener("end", function () { socket.close(); }); @@ -31,7 +31,7 @@ client.addListener("connect", function () { puts("client connected."); }); -client.addListener("receive", function (chunk) { +client.addListener("data", function (chunk) { client_recv_count += 1; puts("client_recv_count " + client_recv_count); assert.equal("hello\r\n", chunk); diff --git a/test/mjsunit/test-tcp-throttle-kernel-buffer.js b/test/mjsunit/test-tcp-throttle-kernel-buffer.js index 9548fa8a36..9c5960ee01 100644 --- a/test/mjsunit/test-tcp-throttle-kernel-buffer.js +++ b/test/mjsunit/test-tcp-throttle-kernel-buffer.js @@ -27,7 +27,7 @@ npauses = 0; var paused = false; client = tcp.createConnection(PORT); client.setEncoding("ascii"); -client.addListener("receive", function (d) { +client.addListener("data", function (d) { chars_recved += d.length; puts("got " + chars_recved); if (!paused) { @@ -45,7 +45,7 @@ client.addListener("receive", function (d) { } }); -client.addListener("eof", function () { +client.addListener("end", function () { server.close(); client.close(); }); diff --git a/test/mjsunit/test-tcp-throttle.js b/test/mjsunit/test-tcp-throttle.js index 2e1e7ac201..d85978b8d2 100644 --- a/test/mjsunit/test-tcp-throttle.js +++ b/test/mjsunit/test-tcp-throttle.js @@ -24,7 +24,7 @@ chars_recved = 0; client = tcp.createConnection(PORT); client.setEncoding("ascii"); -client.addListener("receive", function (d) { +client.addListener("data", function (d) { print(d); recv += d; }); @@ -57,7 +57,7 @@ setTimeout(function () { }, 500); -client.addListener("eof", function () { +client.addListener("end", function () { server.close(); client.close(); }); diff --git a/test/mjsunit/test-tcp-timeout.js b/test/mjsunit/test-tcp-timeout.js index 617b529ff7..d977cc773c 100644 --- a/test/mjsunit/test-tcp-timeout.js +++ b/test/mjsunit/test-tcp-timeout.js @@ -15,12 +15,12 @@ var echo_server = tcp.createServer(function (socket) { p(timeouttime); }); - socket.addListener("receive", function (d) { + socket.addListener("data", function (d) { p(d); socket.send(d); }); - socket.addListener("eof", function () { + socket.addListener("end", function () { socket.close(); }); }); @@ -36,7 +36,7 @@ client.addListener("connect", function () { client.send("hello\r\n"); }); -client.addListener("receive", function (chunk) { +client.addListener("data", function (chunk) { assert.equal("hello\r\n", chunk); if (exchanges++ < 5) { setTimeout(function () { @@ -57,8 +57,8 @@ client.addListener("timeout", function () { assert.equal(false, true); }); -client.addListener("eof", function () { - puts("client eof"); +client.addListener("end", function () { + puts("client end"); client.close(); }); diff --git a/test/mjsunit/test-tcp-tls.js b/test/mjsunit/test-tcp-tls.js index f4abc6890b..8ea488271d 100644 --- a/test/mjsunit/test-tcp-tls.js +++ b/test/mjsunit/test-tcp-tls.js @@ -21,7 +21,7 @@ function tlsTest (port, host, caPem, keyPem, certPem) { socket.setNoDelay(); socket.timeout = 0; - socket.addListener("receive", function (data) { + socket.addListener("data", function (data) { var verified = socket.verifyPeer(); var peerDN = socket.getPeerCertificate("DNstring"); assert.equal(verified, 1); @@ -35,7 +35,7 @@ function tlsTest (port, host, caPem, keyPem, certPem) { } }); - socket.addListener("eof", function () { + socket.addListener("end", function () { assert.equal("writeOnly", socket.readyState); socket.close(); }); @@ -65,7 +65,7 @@ function tlsTest (port, host, caPem, keyPem, certPem) { client.send("PING"); }); - client.addListener("receive", function (data) { + client.addListener("data", function (data) { assert.equal("PONG", data); count += 1;