Update stream API: forceClose() -> destroy(), close() -> end()
authorRyan Dahl <ry@tinyclouds.org>
Thu, 8 Apr 2010 17:44:22 +0000 (10:44 -0700)
committerRyan Dahl <ry@tinyclouds.org>
Thu, 8 Apr 2010 19:24:29 +0000 (12:24 -0700)
32 files changed:
benchmark/http_simple.js
lib/fs.js
lib/http.js
lib/net.js
test/pummel/test-http-client-reconnect-bug.js
test/pummel/test-keep-alive.js
test/pummel/test-tcp-many-clients.js
test/pummel/test-tcp-pause.js
test/pummel/test-tcp-pingpong-delay.js
test/pummel/test-tcp-pingpong.js
test/pummel/test-tcp-throttle.js
test/pummel/test-tcp-timeout.js
test/pummel/test-tcp-tls.js
test/simple/test-child-process-ipc.js
test/simple/test-child-process-stdin.js
test/simple/test-file-read-stream.js
test/simple/test-file-write-stream.js
test/simple/test-http-1.0.js
test/simple/test-http-cat.js
test/simple/test-http-chunked.js
test/simple/test-http-client-race.js
test/simple/test-http-client-upload.js
test/simple/test-http-malformed-request.js
test/simple/test-http-proxy.js
test/simple/test-http-server.js
test/simple/test-http-tls.js
test/simple/test-http-wget.js
test/simple/test-http.js
test/simple/test-net-pingpong.js
test/simple/test-remote-module-loading.js
test/simple/test-tcp-binary.js
test/simple/test-tcp-reconnect.js

index 4d9369c..28c215a 100644 (file)
@@ -1,7 +1,7 @@
 path = require("path");
 
 var puts = require("sys").puts;
-var old = true;
+var old = false;
 
 http = require(old ? "http_old" : 'http');
 if (old) puts('old version');
@@ -56,6 +56,6 @@ http.createServer(function (req, res) {
     res.write(body, 'ascii');
     res.close();
   } else {
-    res.close(body, 'ascii');
+    res.end(body, 'ascii');
   }
 }).listen(8000);
index 25ce376..2157bc1 100644 (file)
--- a/lib/fs.js
+++ b/lib/fs.js
@@ -526,7 +526,7 @@ FileReadStream.prototype._read = function () {
 
     if (bytesRead === 0) {
       self.emit('end');
-      self.forceClose();
+      self.destroy();
       return;
     }
 
@@ -547,7 +547,18 @@ FileReadStream.prototype._read = function () {
 };
 
 
+var readStreamForceCloseWarning;
+
 FileReadStream.prototype.forceClose = function (cb) {
+  if (!readStreamForceCloseWarning) {
+    readStreamForceCloseWarning = "FileReadStream.prototype.forceClose renamed to destroy()";
+    sys.error(readStreamForceCloseWarning);
+  }
+  return this.destroy(cb);
+}
+
+
+FileReadStream.prototype.destroy = function (cb) {
   var self = this;
   this.readable = false;
 
@@ -691,13 +702,35 @@ FileWriteStream.prototype.write = function(data, cb) {
 };
 
 
+var writeStreamCloseWarning;
+
 FileWriteStream.prototype.close = function (cb) {
+  if (!writeStreamCloseWarning) {
+    writeStreamCloseWarning = "FileWriteStream.prototype.close renamed to end()";
+    sys.error(writeStreamCloseWarning); 
+  }
+  return this.end(cb);
+}
+
+
+FileWriteStream.prototype.end = function (cb) {
   this.writeable = false;
   this._queue.push([fs.close, cb]);
   this.flush();
 };
 
 
+var writeStreamForceCloseWarning;
+
+FileWriteStream.prototype.forceClose = function (cb) {
+  if (!writeStreamForceCloseWarning) {
+    writeStreamForceCloseWarning = "FileWriteStream.prototype.forceClose renamed to destroy()";
+    sys.error(writeStreamForceCloseWarning);
+  }
+  return this.destroy(cb);
+}
+
+
 FileWriteStream.prototype.forceClose = function (cb) {
   this.writeable = false;
   fs.close(self.fd, function(err) {
index 353c7da..d0ae306 100644 (file)
@@ -372,7 +372,17 @@ OutgoingMessage.prototype.finish = function () {
   throw new Error("finish() has been renamed to close().");
 };
 
+var closeWarning;
+
 OutgoingMessage.prototype.close = function (data, encoding) {
+  if (!closeWarning) {
+    closeWarning = "OutgoingMessage.prototype.close has been renamed to end()";
+    sys.error(closeWarning);
+  }
+  return this.end(data, encoding);
+};
+
+OutgoingMessage.prototype.end = function (data, encoding) {
   if (data) this.write(data, encoding);
   if (this.chunkedEncoding) this._send("0\r\n\r\n"); // last chunk
   this.finished = true;
@@ -436,19 +446,34 @@ sys.inherits(ClientRequest, OutgoingMessage);
 exports.ClientRequest = ClientRequest;
 
 ClientRequest.prototype.finish = function () {
-  throw new Error( "finish() has been renamed to close() and no longer takes "
+  throw new Error( "finish() has been renamed to end() and no longer takes "
                  + "a response handler as an argument. Manually add a 'response' listener "
                  + "to the request object."
                  );
 };
 
+var clientRequestCloseWarning;
+
 ClientRequest.prototype.close = function () {
+  if (!clientRequestCloseWarning) {
+    clientRequestCloseWarning = "Warning: ClientRequest.prototype.close has been renamed to end()";
+    sys.error(clientRequestCloseWarning);
+  }
+  if (arguments.length > 0) {
+    throw new Error( "ClientRequest.prototype.end does not take any arguments. "
+                   + "Add a response listener manually to the request object."
+                   );
+  }
+  return this.end();
+};
+
+ClientRequest.prototype.end = function () {
   if (arguments.length > 0) {
-    throw new Error( "ClientRequest.prototype.close does not take any arguments. "
+    throw new Error( "ClientRequest.prototype.end does not take any arguments. "
                    + "Add a response listener manually to the request object."
                    );
   }
-  OutgoingMessage.prototype.close.call(this);
+  OutgoingMessage.prototype.end.call(this);
 };
 
 
@@ -509,7 +534,7 @@ function connectionListener (socket) {
     freeParser(parser);
 
     if (responses.length == 0) {
-      socket.close();
+      socket.end();
     } else {
       responses[responses.length-1].closeOnFinish = true;
     }
@@ -525,7 +550,7 @@ function connectionListener (socket) {
     res.shouldKeepAlive = shouldKeepAlive;
     res.addListener('flush', function () {
       if (flushMessageQueue(socket, responses)) {
-        socket.close();
+        socket.end();
       }
     });
     responses.push(res);
@@ -582,7 +607,7 @@ function Client ( ) {
     parser.finish();
 
     debug("self got end closing. readyState = " + self.readyState);
-    self.close();
+    self.end();
   });
 
   self.addListener("close", function (e) {
@@ -604,7 +629,7 @@ function Client ( ) {
 
     res.addListener('end', function ( ) {
       debug("request complete disconnecting. readyState = " + self.readyState);
-      self.close();
+      self.end();
     });
 
     currentRequest.emit("response", res);
@@ -697,7 +722,7 @@ exports.cat = function (url, encoding_, headers_) {
   req.addListener('response', function (res) {
     if (res.statusCode < 200 || res.statusCode >= 300) {
       if (callback) callback(res.statusCode);
-      client.close();
+      client.end();
       return;
     }
     res.setBodyEncoding(encoding);
@@ -711,5 +736,5 @@ exports.cat = function (url, encoding_, headers_) {
     if (callback) callback(err);
   });
 
-  req.close();
+  req.end();
 };
index 9968b66..ff616eb 100644 (file)
@@ -136,7 +136,7 @@ var timeout = new (function () {
             remove(first);
             assert(first != peek(list));
             first.emit('timeout');
-            first.forceClose(new Error('idle timeout'));
+            first.destroy(new Error('idle timeout'));
           }
         }
         debug(msecs + ' list empty');
@@ -277,7 +277,7 @@ function initStream (self) {
                        pool.used,
                        pool.length - pool.used);
     } catch (e) {
-      self.forceClose(e);
+      self.destroy(e);
       return;
     }
 
@@ -290,7 +290,7 @@ function initStream (self) {
       if (self._events && self._events['end']) self.emit('end');
       if (self.onend) self.onend();
 
-      if (!self.writable) self.forceClose();
+      if (!self.writable) self.destroy();
     } else if (bytesRead > 0) {
 
       timeout.active(self);
@@ -485,7 +485,7 @@ Stream.prototype._writeOut = function (data, encoding) {
   try {
     bytesWritten = write(this.fd, buffer, off, len);
   } catch (e) {
-    this.forceClose(e);
+    this.destroy(e);
     return false;
   }
 
@@ -563,7 +563,7 @@ function doConnect (socket, port, host) {
   try {
     connect(socket.fd, port, host);
   } catch (e) {
-    socket.forceClose(e);
+    socket.destroy(e);
     return;
   }
 
@@ -589,7 +589,7 @@ function doConnect (socket, port, host) {
       socket._writeWatcher.callback = _doFlush;
       socket.emit('connect');
     } else if (errno != EINPROGRESS) {
-      socket.forceClose(errnoException(errno, 'connect'));
+      socket.destroy(errnoException(errno, 'connect'));
     }
   };
 }
@@ -660,7 +660,18 @@ Stream.prototype.resume = function () {
 };
 
 
-Stream.prototype.forceClose = function (exception) {
+var forceCloseWarning;
+
+Stream.prototype.forceClose = function (e) {
+  if (!forceCloseWarning) {
+    forceCloseWarning = "forceClose() has been renamed to destroy()";
+    sys.error(forceCloseWarning);
+  }
+  return this.destroy(e);
+};
+
+
+Stream.prototype.destroy = function (exception) {
   // pool is shared between sockets, so don't need to free it here.
   var self = this;
 
@@ -701,18 +712,27 @@ Stream.prototype._shutdown = function () {
     try {
       shutdown(this.fd, 'write')
     } catch (e) {
-      this.forceClose(e);
+      this.destroy(e);
       return;
     }
 
-    if (!this.readable) this.forceClose();
+    if (!this.readable) this.destroy();
   }
 };
 
+var closeDepricationWarning;
 
 Stream.prototype.close = function (data, encoding) {
-  if (data) this.write(data, encoding);
+  if (!closeDepricationWarning) {
+    closeDepricationWarning = "Notification: Stream.prototype.close has been renamed to end()";
+    sys.error(closeDepricationWarning);
+  }
+  return this.end(data, encoding);
+};
+
+Stream.prototype.end = function (data, encoding) {
   if (this.writable) {
+    if (data) this.write(data, encoding);
     if (this._writeQueueLast() != END_OF_FILE) {
       this._writeQueue.push(END_OF_FILE);
       this.flush();
index bdc709d..2e963bb 100644 (file)
@@ -8,7 +8,7 @@ var errorCount = 0;
 var eofCount = 0;
 
 var server = tcp.createServer(function(socket) {
-  socket.close();
+  socket.end();
 });
 server.listen(PORT);
 
@@ -28,7 +28,7 @@ var request = client.request("GET", "/", {"host": "localhost"});
 request.addListener('response', function(response) {
   sys.puts("STATUS: " + response.statusCode);
 });
-request.close();
+request.end();
 
 setTimeout(function () {
   server.close();
index 5b71d4b..cc81dfc 100644 (file)
@@ -10,7 +10,7 @@ server = http.createServer(function (req, res) {
     "Content-Type": "text/plain", 
   });
   res.write(body);
-  res.close();
+  res.end();
 });
 server.listen(PORT);
 
index 1c27169..9ba72a7 100644 (file)
@@ -18,7 +18,7 @@ var server = net.createServer(function (c) {
     total_connections++;
     print("#");
     c.write(body);
-    c.close();
+    c.end();
   });
 });
 server.listen(PORT);
@@ -41,7 +41,7 @@ function runClient (callback) {
   });
 
   client.addListener("end", function () {
-    client.close();
+    client.end();
   });
 
   client.addListener("error", function (e) {
index adb6154..de84c0e 100644 (file)
@@ -5,7 +5,7 @@ N = 200;
 server = net.createServer(function (connection) {
   function write (j) {
     if (j >= N) {
-      connection.close();
+      connection.end();
       return;
     }
     setTimeout(function () {
@@ -58,7 +58,7 @@ setTimeout(function () {
 
 client.addListener("end", function () {
   server.close();
-  client.close();
+  client.end();
 });
 
 process.addListener("exit", function () {
index a2015c3..5854674 100644 (file)
@@ -8,7 +8,7 @@ function pingPongTest (port, host, on_complete) {
   var N = 100;
   var DELAY = 1;
   var count = 0;
-  var client_closed = false;
+  var client_ended = false;
 
   var server = net.createServer(function (socket) {
     socket.setEncoding("utf8");
@@ -32,11 +32,11 @@ function pingPongTest (port, host, on_complete) {
     socket.addListener("end", function () {
       puts("server-side socket EOF");
       assert.equal("writeOnly", socket.readyState);
-      socket.close();
+      socket.end();
     });
 
     socket.addListener("close", function (had_error) {
-      puts("server-side socket close");
+      puts("server-side socket.end");
       assert.equal(false, had_error);
       assert.equal("closed", socket.readyState);
       socket.server.close();
@@ -64,8 +64,8 @@ function pingPongTest (port, host, on_complete) {
         client.write("PING");
       } else {
         puts("closing client");
-        client.close();
-        client_closed = true;
+        client.end();
+        client_ended = true;
       }
     }, DELAY);
   });
@@ -76,9 +76,9 @@ function pingPongTest (port, host, on_complete) {
   });
 
   client.addListener("close", function () {
-    puts("client close");
+    puts("client.end");
     assert.equal(N+1, count);
-    assert.equal(true, client_closed);
+    assert.ok(client_ended);
     if (on_complete) on_complete();
     tests_run += 1;
   });
index c9a66ff..d96e398 100644 (file)
@@ -33,7 +33,7 @@ function pingPongTest (port, host, on_complete) {
 
     socket.addListener("end", function () {
       assert.equal("writeOnly", socket.readyState);
-      socket.close();
+      socket.end();
     });
 
     socket.addListener("close", function (had_error) {
@@ -71,7 +71,7 @@ function pingPongTest (port, host, on_complete) {
     } else {
       sent_final_ping = true;
       client.write("PING");
-      client.close();
+      client.end();
     }
   });
 
index 029d364..8da7239 100644 (file)
@@ -13,7 +13,7 @@ puts("start server on port " + PORT);
 server = net.createServer(function (connection) {
   connection.addListener("connect", function () {
     assert.equal(false, connection.write(body));
-    connection.close();
+    connection.end();
   });
 });
 server.listen(PORT);
@@ -46,7 +46,7 @@ client.addListener("data", function (d) {
 
 client.addListener("end", function () {
   server.close();
-  client.close();
+  client.end();
 });
 
 process.addListener("exit", function () {
index fe82ab3..4279daf 100644 (file)
@@ -20,7 +20,7 @@ var echo_server = net.createServer(function (socket) {
   });
 
   socket.addListener("end", function () {
-    socket.close();
+    socket.end();
   });
 });
 
@@ -58,7 +58,7 @@ client.addListener("timeout", function () {
 
 client.addListener("end", function () {
   puts("client end");
-  client.close();
+  client.end();
 });
 
 client.addListener("close", function () {
index 55612d6..d156b93 100644 (file)
@@ -37,7 +37,7 @@ function tlsTest (port, host, caPem, keyPem, certPem) {
 
     socket.addListener("end", function () {
       assert.equal("writeOnly", socket.readyState);
-      socket.close();
+      socket.end();
     });
 
     socket.addListener("close", function (had_error) {
@@ -83,7 +83,7 @@ function tlsTest (port, host, caPem, keyPem, certPem) {
     } else {
       sent_final_ping = true;
       client.write("PING");
-      client.close();
+      client.end();
     }
   });
 
index ca28462..3b98812 100644 (file)
@@ -26,7 +26,7 @@ child.stdout.addListener("data", function (data){
   } else {
     assert.equal("echo me\r\n", data);
     gotEcho = true;
-    child.stdin.close();
+    child.stdin.end();
   }
 });
 
index d60740c..6521f43 100644 (file)
@@ -6,7 +6,7 @@ var cat = spawn("cat");
 cat.stdin.write("hello");
 cat.stdin.write(" ");
 cat.stdin.write("world");
-cat.stdin.close();
+cat.stdin.end();
 
 var response = "";
 var exitStatus = -1;
index de8ff63..a7fa8b6 100644 (file)
@@ -10,7 +10,7 @@ var
     open: -1,
     end: -1,
     close: -1,
-    forceClose: -1
+    destroy: -1
   },
 
   paused = false,
@@ -51,9 +51,9 @@ file
   });
 
 var file2 = fs.createReadStream(fn);
-file2.forceClose(function(err) {
+file2.destroy(function(err) {
   assert.ok(!err);
-  callbacks.forceClose++;
+  callbacks.destroy++;
 });
 
 process.addListener('exit', function() {
index df04599..51beb8c 100644 (file)
@@ -12,7 +12,7 @@ var
     open: -1,
     drain: -2,
     close: -1,
-    closeCb: -1,
+    endCb: -1,
     write: -11,
   };
 
@@ -31,9 +31,9 @@ file
       file.write(EXPECTED);
     } else if (callbacks.drain == 0) {
       assert.equal(EXPECTED+EXPECTED, fs.readFileSync(fn));
-      file.close(function(err) {
+      file.end(function(err) {
         assert.ok(!err);
-        callbacks.closeCb++;
+        callbacks.endCb++;
       });
     }
   })
index 3a8cd0e..248c7fc 100644 (file)
@@ -8,7 +8,7 @@ var client_got_eof = false;
 
 var server = http.createServer(function (req, res) {
   res.writeHead(200, {"Content-Type": "text/plain"});
-  res.close(body);
+  res.end(body);
 })
 server.listen(PORT);
 
@@ -27,7 +27,7 @@ c.addListener("data", function (chunk) {
 
 c.addListener("end", function () {
   client_got_eof = true;
-  c.close();
+  c.end();
   server.close();
 });
 
index f270ca9..179298e 100644 (file)
@@ -8,7 +8,7 @@ var server = http.createServer(function (req, res) {
     ["Content-Length", body.length],
     ["Content-Type", "text/plain"]
   ]);
-  res.close(body);
+  res.end(body);
 });
 server.listen(PORT);
 
index bb065de..b1168eb 100644 (file)
@@ -5,7 +5,7 @@ var UTF8_STRING = "南越国是前203年至前111年存在于岭南地区的一
 
 var server = http.createServer(function(req, res) {
   res.writeHead(200, {"Content-Type": "text/plain; charset=utf8"});
-  res.close(UTF8_STRING, 'utf8');
+  res.end(UTF8_STRING, 'utf8');
 });
 server.listen(PORT);
 
index b9b0df4..e669648 100644 (file)
@@ -10,7 +10,7 @@ var server = http.createServer(function (req, res) {
   res.writeHead(200, { "Content-Type": "text/plain"
                       , "Content-Length": body.length
                       });
-  res.close(body);
+  res.end(body);
 });
 server.listen(PORT);
 
@@ -34,10 +34,10 @@ req1.addListener('response', function (res1) {
       res2.addListener('data', function (chunk) { body2 += chunk; });
       res2.addListener('end', function () { server.close(); });
     });
-    req2.close();
+    req2.end();
   });
 });
-req1.close();
+req1.end();
 
 process.addListener("exit", function () {
   assert.equal(body1_s, body1);
index b4c0f61..ce7887a 100644 (file)
@@ -19,7 +19,7 @@ var server = http.createServer(function(req, res) {
     puts("request complete from server");
     res.writeHead(200, {'Content-Type': 'text/plain'});
     res.write('hello\n');
-    res.close();
+    res.end();
   });
 });
 server.listen(PORT);
@@ -42,7 +42,7 @@ req.addListener('response', function(res) {
     server.close();
   });
 });
-req.close();
+req.end();
 
 process.addListener("exit", function () {
   assert.equal("1\n2\n3\n", sent_body);
index 47bcfca..e93fba9 100644 (file)
@@ -14,7 +14,7 @@ var s = http.createServer(function (req, res) {
 
   res.writeHead(200, {"Content-Type": "text/plain"});
   res.write("Hello World");
-  res.close();
+  res.end();
 
   if (++nrequests_completed == nrequests_expected) s.close();
 });
@@ -23,7 +23,7 @@ s.listen(PORT);
 var c = net.createConnection(PORT);
 c.addListener("connect", function () {
   c.write("GET /hello?foo=%99bar HTTP/1.1\r\n\r\n");
-  c.close();
+  c.end();
 });
 
 //  TODO add more!
index 348851d..ffaec76 100644 (file)
@@ -9,7 +9,7 @@ var backend = http.createServer(function (req, res) {
   debug("backend request");
   res.writeHead(200, {"content-type": "text/plain"});
   res.write("hello world\n");
-  res.close();
+  res.end();
 });
 debug("listen backend")
 backend.listen(BACKEND_PORT);
@@ -24,11 +24,11 @@ var proxy = http.createServer(function (req, res) {
       res.write(chunk);
     });
     proxy_res.addListener("end", function() {
-      res.close();
+      res.end();
       debug("proxy res");
     });
   });
-  proxy_req.close();
+  proxy_req.end();
 });
 debug("listen proxy")
 proxy.listen(PROXY_PORT);
@@ -54,7 +54,7 @@ function startReq () {
        debug("closed both");
     });
   });
-  req.close();
+  req.end();
 }
 
 proxy.addListener('listening', startReq);
index c7deeb8..ec24957 100644 (file)
@@ -38,7 +38,7 @@ http.createServer(function (req, res) {
   setTimeout(function () {
     res.writeHead(200, {"Content-Type": "text/plain"});
     res.write(url.parse(req.url).pathname);
-    res.close();
+    res.end();
   }, 1);
 
 }).listen(PORT);
@@ -63,7 +63,7 @@ c.addListener("data", function (chunk) {
   if (requests_sent == 2) {
     c.write("GET / HTTP/1.1\r\nX-X: foo\r\n\r\n"
            +"GET / HTTP/1.1\r\nX-X: bar\r\n\r\n");
-    c.close();
+    c.end();
     assert.equal(c.readyState, "readOnly");
     requests_sent += 2;
   }
index 0784829..9218133 100644 (file)
@@ -54,7 +54,7 @@ var http_server=http.createServer(function (req, res) {
   req.addListener('end', function () {
     res.writeHead(200, {"Content-Type": "text/plain"});
     res.write("The path was " + url.parse(req.url).pathname);
-    res.close();
+    res.end();
     responses_sent += 1;
   });
 
@@ -78,7 +78,7 @@ req.addListener('response', function (res) {
   res.addListener('data', function (chunk) { body0 += chunk; });
   debug("Got /hello response");
 });
-req.close();
+req.end();
 
 setTimeout(function () {
   req = client.request("POST", "/world");
@@ -94,7 +94,7 @@ setTimeout(function () {
     res.addListener('data', function (chunk) { body1 += chunk; });
     debug("Got /world response");
   });
-  req.close();
+  req.end();
 }, 1);
 
 process.addListener("exit", function () {
index 1d7f341..47e215e 100644 (file)
@@ -25,7 +25,7 @@ var server = http.createServer(function (req, res) {
   res.writeHead(200, {"Content-Type": "text/plain"});
   res.write("hello ");
   res.write("world\n");
-  res.close();
+  res.end();
 })
 server.listen(PORT);
 
@@ -46,7 +46,7 @@ c.addListener("data", function (chunk) {
 c.addListener("end", function () {
   client_got_eof = true;
   puts('got end');
-  c.close();
+  c.end();
 });
 
 c.addListener("close", function () {
index c599277..f1da37c 100644 (file)
@@ -29,7 +29,7 @@ http.createServer(function (req, res) {
   req.addListener('end', function () {
     res.writeHead(200, {"Content-Type": "text/plain"});
     res.write("The path was " + url.parse(req.url).pathname);
-    res.close();
+    res.end();
     responses_sent += 1;
   });
 
@@ -45,7 +45,7 @@ req.addListener('response', function (res) {
   res.addListener('data', function (chunk) { body0 += chunk; });
   debug("Got /hello response");
 });
-req.close();
+req.end();
 
 setTimeout(function () {
   req = client.request("POST", "/world");
@@ -56,7 +56,7 @@ setTimeout(function () {
     res.addListener('data', function (chunk) { body1 += chunk; });
     debug("Got /world response");
   });
-  req.close();
+  req.end();
 }, 1);
 
 process.addListener("exit", function () {
index ed8cfeb..cf977dc 100644 (file)
@@ -30,7 +30,7 @@ function pingPongTest (port, host) {
     socket.addListener("end", function () {
       assert.equal(true, socket.writable);
       assert.equal(false, socket.readable);
-      socket.close();
+      socket.end();
     });
 
     socket.addListener("error", function (e) {
@@ -38,7 +38,7 @@ function pingPongTest (port, host) {
     });
 
     socket.addListener("close", function () {
-      puts('server socket closed');
+      puts('server socket.endd');
       assert.equal(false, socket.writable);
       assert.equal(false, socket.readable);
       socket.server.close();
@@ -77,12 +77,12 @@ function pingPongTest (port, host) {
       } else {
         sent_final_ping = true;
         client.write("PING");
-        client.close();
+        client.end();
       }
     });
 
     client.addListener("close", function () {
-      puts('client closed');
+      puts('client.endd');
       assert.equal(N+1, count);
       assert.equal(true, sent_final_ping);
       tests_run += 1;
index 0a2af87..00a0974 100644 (file)
@@ -12,7 +12,7 @@ var server = http.createServer(function(req, res) {
 
   res.writeHead(200, {'Content-Type': 'text/javascript'});
   res.write(body);
-  res.close();
+  res.end();
 });
 server.listen(PORT);
 
index e1d8554..9dc347a 100644 (file)
@@ -25,7 +25,7 @@ var echoServer = tcp.createServer(function (connection) {
     connection.write(chunk, "binary");
   });
   connection.addListener("end", function () {
-    connection.close();
+    connection.end();
   });
 });
 echoServer.listen(PORT);
@@ -42,7 +42,7 @@ c.addListener("data", function (chunk) {
     c.write(String.fromCharCode(j), "binary");
     j++;
   } else {
-    c.close();
+    c.end();
   }
   recv += chunk;
 });
index 66d93e3..143c4ac 100644 (file)
@@ -12,7 +12,7 @@ var server = net.createServer(function (socket) {
   });
 
   socket.addListener("end", function () {
-    socket.close();
+    socket.end();
   });
 
   socket.addListener("close", function (had_error) {
@@ -37,7 +37,7 @@ server.addListener('listening', function () {
     client_recv_count += 1;
     puts("client_recv_count " + client_recv_count);
     assert.equal("hello\r\n", chunk);
-    client.close();
+    client.end();
   });
 
   client.addListener("close", function (had_error) {