API: tcp events 'receive' to 'data', 'eof' to 'end'
authorRyan Dahl <ry@tinyclouds.org>
Fri, 12 Feb 2010 08:25:15 +0000 (00:25 -0800)
committerRyan Dahl <ry@tinyclouds.org>
Fri, 12 Feb 2010 08:25:19 +0000 (00:25 -0800)
No deprecation messages. Not sure how...

18 files changed:
doc/api.txt
lib/http.js
src/node_http.cc
src/node_net.cc
test/mjsunit/test-http-1.0.js
test/mjsunit/test-http-client-reconnect-bug.js
test/mjsunit/test-http-server.js
test/mjsunit/test-http-wget.js
test/mjsunit/test-stdio.js
test/mjsunit/test-tcp-binary.js
test/mjsunit/test-tcp-many-clients.js
test/mjsunit/test-tcp-pingpong-delay.js
test/mjsunit/test-tcp-pingpong.js
test/mjsunit/test-tcp-reconnect.js
test/mjsunit/test-tcp-throttle-kernel-buffer.js
test/mjsunit/test-tcp-throttle.js
test/mjsunit/test-tcp-timeout.js
test/mjsunit/test-tcp-tls.js

index 87af8b0..4cd0d95 100644 (file)
@@ -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()+::
index dcb152e..d455506 100644 (file)
@@ -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();
   });
 
index 9794b90..4f49967 100644 (file)
@@ -27,7 +27,7 @@ static Persistent<String> header_field_symbol;
 static Persistent<String> header_value_symbol;
 static Persistent<String> header_complete_symbol;
 static Persistent<String> body_symbol;
-static Persistent<String> eof_symbol;
+static Persistent<String> end_symbol;
 
 static Persistent<String> delete_sym;
 static Persistent<String> get_sym;
@@ -66,7 +66,7 @@ HTTPConnection::Initialize (Handle<Object> 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
index dad2906..4704c73 100644 (file)
@@ -32,12 +32,12 @@ static Persistent<String> write_only_symbol;
 static Persistent<String> closing_symbol;
 static Persistent<String> closed_symbol;
 
-static Persistent<String> receive_symbol;
+static Persistent<String> data_symbol;
 static Persistent<String> connection_symbol;
 static Persistent<String> connect_symbol;
 static Persistent<String> timeout_symbol;
 static Persistent<String> drain_symbol;
-static Persistent<String> eof_symbol;
+static Persistent<String> end_symbol;
 static Persistent<String> close_symbol;
 
 static const struct addrinfo server_tcp_hints =
@@ -76,12 +76,12 @@ void Connection::Initialize(v8::Handle<v8::Object> 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<FunctionTemplate> t = FunctionTemplate::New(New);
@@ -618,7 +618,7 @@ Handle<Value> Connection::Send(const Arguments& args) {
 void Connection::OnReceive(const void *buf, size_t len) {
   HandleScope scope;
   Local<Value> 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<FunctionTemplate> Server::constructor_template;
index ffc69e0..9fc0a5d 100644 (file)
@@ -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();
index 16a63f9..c8d2999 100644 (file)
@@ -21,7 +21,7 @@ client.addListener("error", function() {
   errorCount++;
 });
 
-client.addListener("eof", function() {
+client.addListener("end", function() {
   sys.puts("EOF!");
   eofCount++;
 });
index 63e394b..35b05f2 100644 (file)
@@ -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;
 });
 
index 3073c1d..33c477f 100644 (file)
@@ -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();
 });
 
index e8bc684..786e9e1 100644 (file)
@@ -24,7 +24,7 @@ child.addListener("output", function (data){
       child.close();
     }
   } else {
-    puts('child eof');
+    puts('child end');
   }
 });
 
index b91f2a6..5ce6b9a 100644 (file)
@@ -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");
index 0dfda16..69fb145 100644 (file)
@@ -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();
   });
 
index 726ca7d..d7d2beb 100644 (file)
@@ -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);
index 89d5329..543fcfe 100644 (file)
@@ -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;
 
index 4832838..6d2a125 100644 (file)
@@ -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);
index 9548fa8..9c5960e 100644 (file)
@@ -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();
 });
index 2e1e7ac..d85978b 100644 (file)
@@ -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();
 });
index 617b529..d977cc7 100644 (file)
@@ -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();
 });
 
index f4abc68..8ea4882 100644 (file)
@@ -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;