Change 'new node.tcp.Connection' to 'node.tcp.createConnection'
authorRyan <ry@tinyclouds.org>
Tue, 30 Jun 2009 11:56:52 +0000 (13:56 +0200)
committerRyan <ry@tinyclouds.org>
Tue, 30 Jun 2009 11:56:52 +0000 (13:56 +0200)
src/node.js
test/mjsunit/test-http-server.js
test/mjsunit/test-reconnecting-socket.js
test/mjsunit/test-tcp-pingpong.js
website/api.txt

index a4faaf0..6b2aaec 100644 (file)
@@ -11,6 +11,12 @@ node.createProcess = function (command) {
   return process;
 };
 
+node.tcp.createConnection = function (port, host) {
+  var connection = new node.tcp.Connection();
+  connection.connect(port, host);
+  return connection;
+};
+
 // Timers
 
 function setTimeout (callback, after) {
index 6450727..fa726e2 100644 (file)
@@ -33,8 +33,10 @@ function onLoad() {
 
   }).listen(port);
 
-  var c = new node.tcp.Connection();
+  var c = node.tcp.createConnection(port);
+
   c.setEncoding("utf8");
+
   c.addListener("connect", function () {
     c.send( "GET /hello HTTP/1.1\r\n\r\n" );
     requests_sent += 1;
@@ -58,8 +60,6 @@ function onLoad() {
   c.addListener("disconnect", function () {
     assertEquals(c.readyState, "closed");
   });
-
-  c.connect(port);
 }
 
 function onExit () {
index 39bb9d8..dcdf436 100644 (file)
@@ -22,10 +22,13 @@ function onLoad () {
     });
   });
   server.listen(port);
-  var client = new node.tcp.Connection();
+  
+  var client = node.tcp.createConnection(port);
   
   client.setEncoding("UTF8");
+
   client.addListener("connect", function () {
+    puts("client connected.");
   });
 
   client.addListener("receive", function (chunk) {
@@ -41,8 +44,6 @@ function onLoad () {
     else
       server.close();
   });
-
-  client.connect(port);
 }
 
 function onExit () {
index d97d5b7..eea45c2 100644 (file)
@@ -40,8 +40,7 @@ function pingPongTest (port, host, on_complete) {
   });
   server.listen(port, host);
 
-  var client = new node.tcp.Connection();
-  assertEquals("closed", client.readyState);
+  var client = node.tcp.createConnection(port, host);
 
   client.setEncoding("utf8");
 
@@ -76,9 +75,6 @@ function pingPongTest (port, host, on_complete) {
     if (on_complete) on_complete();
     tests_run += 1;
   });
-
-  assertEquals("closed", client.readyState);
-  client.connect(port, host);
 }
 
 function onLoad () {
index 19c1c21..c0add09 100644 (file)
@@ -952,12 +952,9 @@ socket for +node.tcp.Server+.
                                   (TODO: access error codes.)
 |=========================================================
 
-+new node.tcp.Connection()+::
-  Creates a new connection object.
-
-
-+connection.connect(port, host="127.0.0.1")+::
-  Opens a connection to the specified +port+ and
++node.tcp.createConnection(port, host="127.0.0.1")+::
+  Creates a new connection object and 
+  opens a connection to the specified +port+ and
   +host+. If the second parameter is omitted, localhost is
   assumed.