Browse Source

Move tcp library to /tcp.js

v0.7.4-release
Ryan Dahl 15 years ago
parent
commit
095470854b
  1. 26
      doc/api.html
  2. 25
      doc/api.txt
  3. 28
      doc/api.xml
  4. 24
      doc/node.1
  5. 12
      lib/tcp.js
  6. 11
      src/node.js
  7. 3
      test/mjsunit/test-http-malformed-request.js
  8. 3
      test/mjsunit/test-http-server.js
  9. 5
      test/mjsunit/test-tcp-binary.js
  10. 5
      test/mjsunit/test-tcp-many-clients.js
  11. 5
      test/mjsunit/test-tcp-pingpong-delay.js
  12. 5
      test/mjsunit/test-tcp-pingpong.js
  13. 5
      test/mjsunit/test-tcp-reconnect.js
  14. 5
      test/mjsunit/test-tcp-throttle-kernel-buffer.js
  15. 5
      test/mjsunit/test-tcp-throttle.js
  16. 5
      test/mjsunit/test-tcp-timeout.js

26
doc/api.html

@ -1015,7 +1015,7 @@ Returns a new web server object.
</p> </p>
<div class="paragraph"><p>The <tt>options</tt> argument is optional. The <div class="paragraph"><p>The <tt>options</tt> argument is optional. The
<tt>options</tt> argument accepts the same values as the <tt>options</tt> argument accepts the same values as the
options argument for <tt>node.tcp.Server</tt> does.</p></div> options argument for <tt>tcp.Server</tt> does.</p></div>
<div class="paragraph"><p>The <tt>request_listener</tt> is a function which is automatically <div class="paragraph"><p>The <tt>request_listener</tt> is a function which is automatically
added to the <tt>"request"</tt> event.</p></div> added to the <tt>"request"</tt> event.</p></div>
</dd> </dd>
@ -1464,12 +1464,15 @@ After emitted no other events will be emitted on the response.</p></td>
</dd> </dd>
</dl></div> </dl></div>
<h3 id="_tcp">TCP</h3><div style="clear:left"></div> <h3 id="_tcp">TCP</h3><div style="clear:left"></div>
<h4 id="_tt_node_tcp_server_tt"><tt>node.tcp.Server</tt></h4> <div class="paragraph"><p>To use the TCP server and client one must <tt>require("/tcp.js")</tt> or
<tt>include("/tcp.js")</tt>.</p></div>
<h4 id="_tt_tcp_server_tt"><tt>tcp.Server</tt></h4>
<div class="paragraph"><p>Here is an example of a echo server which listens for connections <div class="paragraph"><p>Here is an example of a echo server which listens for connections
on port 7000</p></div> on port 7000</p></div>
<div class="listingblock"> <div class="listingblock">
<div class="content"> <div class="content">
<pre><tt>function echo (socket) { <pre><tt>include("/tcp.js");
var server = createServer(function (socket) {
socket.setEncoding("utf8"); socket.setEncoding("utf8");
socket.addListener("connect", function () { socket.addListener("connect", function () {
socket.send("hello\r\n"); socket.send("hello\r\n");
@ -1481,8 +1484,7 @@ on port 7000</p></div>
socket.send("goodbye\r\n"); socket.send("goodbye\r\n");
socket.close(); socket.close();
}); });
} });
var server = node.tcp.createServer(echo);
server.listen(7000, "localhost");</tt></pre> server.listen(7000, "localhost");</tt></pre>
</div></div> </div></div>
<div class="tableblock"> <div class="tableblock">
@ -1505,7 +1507,7 @@ cellspacing="0" cellpadding="4">
<td align="left" valign="top"><p class="table"><tt>"connection"</tt></p></td> <td align="left" valign="top"><p class="table"><tt>"connection"</tt></p></td>
<td align="left" valign="top"><p class="table"><tt>connection</tt></p></td> <td align="left" valign="top"><p class="table"><tt>connection</tt></p></td>
<td align="left" valign="top"><p class="table">Emitted when a new connection is made. <td align="left" valign="top"><p class="table">Emitted when a new connection is made.
<tt>connection</tt> is an instance of <tt>node.tcp.Connection</tt>.</p></td> <tt>connection</tt> is an instance of <tt>tcp.Connection</tt>.</p></td>
</tr> </tr>
<tr> <tr>
<td align="left" valign="top"><p class="table"><tt>"close"</tt></p></td> <td align="left" valign="top"><p class="table"><tt>"close"</tt></p></td>
@ -1520,7 +1522,7 @@ cellspacing="0" cellpadding="4">
</div> </div>
<div class="dlist"><dl> <div class="dlist"><dl>
<dt class="hdlist1"> <dt class="hdlist1">
<tt>node.tcp.createServer(connection_listener);</tt> <tt>tcp.createServer(connection_listener);</tt>
</dt> </dt>
<dd> <dd>
<p> <p>
@ -1554,9 +1556,9 @@ event.
</p> </p>
</dd> </dd>
</dl></div> </dl></div>
<h4 id="_tt_node_tcp_connection_tt"><tt>node.tcp.Connection</tt></h4> <h4 id="_tt_tcp_connection_tt"><tt>tcp.Connection</tt></h4>
<div class="paragraph"><p>This object is used as a TCP client and also as a server-side <div class="paragraph"><p>This object is used as a TCP client and also as a server-side
socket for <tt>node.tcp.Server</tt>.</p></div> socket for <tt>tcp.Server</tt>.</p></div>
<div class="tableblock"> <div class="tableblock">
<table rules="all" <table rules="all"
width="100%" width="100%"
@ -1619,7 +1621,7 @@ cellspacing="0" cellpadding="4">
</div> </div>
<div class="dlist"><dl> <div class="dlist"><dl>
<dt class="hdlist1"> <dt class="hdlist1">
<tt>node.tcp.createConnection(port, host="127.0.0.1")</tt> <tt>tcp.createConnection(port, host="127.0.0.1")</tt>
</dt> </dt>
<dd> <dd>
<p> <p>
@ -1721,7 +1723,7 @@ Resumes reading if reading was paused by <tt>readPause()</tt>.
<dd> <dd>
<p> <p>
Sets the connection to timeout after <tt>timeout</tt> milliseconds of inactivity on Sets the connection to timeout after <tt>timeout</tt> milliseconds of inactivity on
the connection. By default all <tt>node.tcp.Connection</tt> objects have a timeout the connection. By default all <tt>tcp.Connection</tt> objects have a timeout
of 60 seconds (60000 ms). of 60 seconds (60000 ms).
</p> </p>
<div class="paragraph"><p>If <tt>timeout</tt> is 0, then the idle timeout is disabled.</p></div> <div class="paragraph"><p>If <tt>timeout</tt> is 0, then the idle timeout is disabled.</p></div>
@ -1946,7 +1948,7 @@ init (Handle&lt;Object&gt; target)
<div id="footer"> <div id="footer">
<div id="footer-text"> <div id="footer-text">
Version 0.1.12<br /> Version 0.1.12<br />
Last updated 2009-09-28 12:23:06 CEST Last updated 2009-09-28 16:05:24 CEST
</div> </div>
</div> </div>
</body> </body>

25
doc/api.txt

@ -625,7 +625,7 @@ Returns a new web server object.
+ +
The +options+ argument is optional. The The +options+ argument is optional. The
+options+ argument accepts the same values as the +options+ argument accepts the same values as the
options argument for +node.tcp.Server+ does. options argument for +tcp.Server+ does.
+ +
The +request_listener+ is a function which is automatically The +request_listener+ is a function which is automatically
added to the +"request"+ event. added to the +"request"+ event.
@ -942,13 +942,17 @@ After emitted no other events will be emitted on the response.
=== TCP === TCP
==== +node.tcp.Server+ To use the TCP server and client one must +require("/tcp.js")+ or
+include("/tcp.js")+.
==== +tcp.Server+
Here is an example of a echo server which listens for connections Here is an example of a echo server which listens for connections
on port 7000 on port 7000
---------------------------------------- ----------------------------------------
function echo (socket) { include("/tcp.js");
var server = createServer(function (socket) {
socket.setEncoding("utf8"); socket.setEncoding("utf8");
socket.addListener("connect", function () { socket.addListener("connect", function () {
socket.send("hello\r\n"); socket.send("hello\r\n");
@ -960,8 +964,7 @@ function echo (socket) {
socket.send("goodbye\r\n"); socket.send("goodbye\r\n");
socket.close(); socket.close();
}); });
} });
var server = node.tcp.createServer(echo);
server.listen(7000, "localhost"); server.listen(7000, "localhost");
---------------------------------------- ----------------------------------------
@ -970,14 +973,14 @@ server.listen(7000, "localhost");
|========================================================= |=========================================================
|Event | Parameters | Notes |Event | Parameters | Notes
|+"connection"+ | +connection+ | Emitted when a new connection is made. |+"connection"+ | +connection+ | Emitted when a new connection is made.
+connection+ is an instance of +node.tcp.Connection+. +connection+ is an instance of +tcp.Connection+.
|+"close"+ | +errorno+ | Emitted when the server closes. +errorno+ |+"close"+ | +errorno+ | Emitted when the server closes. +errorno+
is an integer which indicates what, if any, is an integer which indicates what, if any,
error caused the server to close. If no error caused the server to close. If no
error occurred +errorno+ will be 0. error occurred +errorno+ will be 0.
|========================================================= |=========================================================
+node.tcp.createServer(connection_listener);+ :: +tcp.createServer(connection_listener);+ ::
Creates a new TCP server. Creates a new TCP server.
+ +
The +connection_listener+ argument is automatically set as a listener for The +connection_listener+ argument is automatically set as a listener for
@ -1003,10 +1006,10 @@ asynchronous, the server is finally closed when the server emits a +"close"+
event. event.
==== +node.tcp.Connection+ ==== +tcp.Connection+
This object is used as a TCP client and also as a server-side This object is used as a TCP client and also as a server-side
socket for +node.tcp.Server+. socket for +tcp.Server+.
[cols="1,2,10",options="header"] [cols="1,2,10",options="header"]
|========================================================= |=========================================================
@ -1034,7 +1037,7 @@ socket for +node.tcp.Server+.
(TODO: access error codes.) (TODO: access error codes.)
|========================================================= |=========================================================
+node.tcp.createConnection(port, host="127.0.0.1")+:: +tcp.createConnection(port, host="127.0.0.1")+::
Creates a new connection object and opens a connection to the specified Creates a new connection object and opens a connection to the specified
+port+ and +host+. If the second parameter is omitted, localhost is assumed. +port+ and +host+. If the second parameter is omitted, localhost is assumed.
+ +
@ -1090,7 +1093,7 @@ Resumes reading if reading was paused by +readPause()+.
+connection.setTimeout(timeout)+:: +connection.setTimeout(timeout)+::
Sets the connection to timeout after +timeout+ milliseconds of inactivity on Sets the connection to timeout after +timeout+ milliseconds of inactivity on
the connection. By default all +node.tcp.Connection+ objects have a timeout the connection. By default all +tcp.Connection+ objects have a timeout
of 60 seconds (60000 ms). of 60 seconds (60000 ms).
+ +
If +timeout+ is 0, then the idle timeout is disabled. If +timeout+ is 0, then the idle timeout is disabled.

28
doc/api.xml

@ -1062,7 +1062,7 @@ Returns a new web server object.
</simpara> </simpara>
<simpara>The <literal>options</literal> argument is optional. The <simpara>The <literal>options</literal> argument is optional. The
<literal>options</literal> argument accepts the same values as the <literal>options</literal> argument accepts the same values as the
options argument for <literal>node.tcp.Server</literal> does.</simpara> options argument for <literal>tcp.Server</literal> does.</simpara>
<simpara>The <literal>request_listener</literal> is a function which is automatically <simpara>The <literal>request_listener</literal> is a function which is automatically
added to the <literal>"request"</literal> event.</simpara> added to the <literal>"request"</literal> event.</simpara>
</listitem> </listitem>
@ -1551,11 +1551,14 @@ After emitted no other events will be emitted on the response.</simpara></entry>
</refsect2> </refsect2>
<refsect2 id="_tcp"> <refsect2 id="_tcp">
<title>TCP</title> <title>TCP</title>
<refsect3 id="_literal_node_tcp_server_literal"> <simpara>To use the TCP server and client one must <literal>require("/tcp.js")</literal> or
<title><literal>node.tcp.Server</literal></title> <literal>include("/tcp.js")</literal>.</simpara>
<refsect3 id="_literal_tcp_server_literal">
<title><literal>tcp.Server</literal></title>
<simpara>Here is an example of a echo server which listens for connections <simpara>Here is an example of a echo server which listens for connections
on port 7000</simpara> on port 7000</simpara>
<screen>function echo (socket) { <screen>include("/tcp.js");
var server = createServer(function (socket) {
socket.setEncoding("utf8"); socket.setEncoding("utf8");
socket.addListener("connect", function () { socket.addListener("connect", function () {
socket.send("hello\r\n"); socket.send("hello\r\n");
@ -1567,8 +1570,7 @@ on port 7000</simpara>
socket.send("goodbye\r\n"); socket.send("goodbye\r\n");
socket.close(); socket.close();
}); });
} });
var server = node.tcp.createServer(echo);
server.listen(7000, "localhost");</screen> server.listen(7000, "localhost");</screen>
<informaltable <informaltable
frame="all" frame="all"
@ -1590,7 +1592,7 @@ rowsep="1" colsep="1"
<entry align="left" valign="top"><simpara><literal>"connection"</literal></simpara></entry> <entry align="left" valign="top"><simpara><literal>"connection"</literal></simpara></entry>
<entry align="left" valign="top"><simpara><literal>connection</literal></simpara></entry> <entry align="left" valign="top"><simpara><literal>connection</literal></simpara></entry>
<entry align="left" valign="top"><simpara>Emitted when a new connection is made. <entry align="left" valign="top"><simpara>Emitted when a new connection is made.
<literal>connection</literal> is an instance of <literal>node.tcp.Connection</literal>.</simpara></entry> <literal>connection</literal> is an instance of <literal>tcp.Connection</literal>.</simpara></entry>
</row> </row>
<row> <row>
<entry align="left" valign="top"><simpara><literal>"close"</literal></simpara></entry> <entry align="left" valign="top"><simpara><literal>"close"</literal></simpara></entry>
@ -1606,7 +1608,7 @@ rowsep="1" colsep="1"
<variablelist> <variablelist>
<varlistentry> <varlistentry>
<term> <term>
<literal>node.tcp.createServer(connection_listener);</literal> <literal>tcp.createServer(connection_listener);</literal>
</term> </term>
<listitem> <listitem>
<simpara> <simpara>
@ -1646,10 +1648,10 @@ event.
</varlistentry> </varlistentry>
</variablelist> </variablelist>
</refsect3> </refsect3>
<refsect3 id="_literal_node_tcp_connection_literal"> <refsect3 id="_literal_tcp_connection_literal">
<title><literal>node.tcp.Connection</literal></title> <title><literal>tcp.Connection</literal></title>
<simpara>This object is used as a TCP client and also as a server-side <simpara>This object is used as a TCP client and also as a server-side
socket for <literal>node.tcp.Server</literal>.</simpara> socket for <literal>tcp.Server</literal>.</simpara>
<informaltable <informaltable
frame="all" frame="all"
rowsep="1" colsep="1" rowsep="1" colsep="1"
@ -1713,7 +1715,7 @@ rowsep="1" colsep="1"
<variablelist> <variablelist>
<varlistentry> <varlistentry>
<term> <term>
<literal>node.tcp.createConnection(port, host="127.0.0.1")</literal> <literal>tcp.createConnection(port, host="127.0.0.1")</literal>
</term> </term>
<listitem> <listitem>
<simpara> <simpara>
@ -1835,7 +1837,7 @@ Resumes reading if reading was paused by <literal>readPause()</literal>.
<listitem> <listitem>
<simpara> <simpara>
Sets the connection to timeout after <literal>timeout</literal> milliseconds of inactivity on Sets the connection to timeout after <literal>timeout</literal> milliseconds of inactivity on
the connection. By default all <literal>node.tcp.Connection</literal> objects have a timeout the connection. By default all <literal>tcp.Connection</literal> objects have a timeout
of 60 seconds (60000 ms). of 60 seconds (60000 ms).
</simpara> </simpara>
<simpara>If <literal>timeout</literal> is 0, then the idle timeout is disabled.</simpara> <simpara>If <literal>timeout</literal> is 0, then the idle timeout is disabled.</simpara>

24
doc/node.1

@ -900,7 +900,7 @@ options
argument is optional\. The argument is optional\. The
options options
argument accepts the same values as the options argument for argument accepts the same values as the options argument for
node\.tcp\.Server tcp\.Server
does\. does\.
.sp .sp
The The
@ -1364,19 +1364,22 @@ that this response belongs to\.
.RE .RE
.RE .RE
.SS "TCP" .SS "TCP"
To use the TCP server and client one must require("/tcp\.js") or include("/tcp\.js")\.
.sp
.sp .sp
.it 1 an-trap .it 1 an-trap
.nr an-no-space-flag 1 .nr an-no-space-flag 1
.nr an-break-flag 1 .nr an-break-flag 1
.br .br
node.tcp.Server tcp.Server
.RS .RS
Here is an example of a echo server which listens for connections on port 7000 Here is an example of a echo server which listens for connections on port 7000
.sp .sp
.sp .sp
.RS 4 .RS 4
.nf .nf
function echo (socket) { include("/tcp\.js");
var server = createServer(function (socket) {
socket\.setEncoding("utf8"); socket\.setEncoding("utf8");
socket\.addListener("connect", function () { socket\.addListener("connect", function () {
socket\.send("hello\er\en"); socket\.send("hello\er\en");
@ -1388,8 +1391,7 @@ function echo (socket) {
socket\.send("goodbye\er\en"); socket\.send("goodbye\er\en");
socket\.close(); socket\.close();
}); });
} });
var server = node\.tcp\.createServer(echo);
server\.listen(7000, "localhost"); server\.listen(7000, "localhost");
.fi .fi
.RE .RE
@ -1413,7 +1415,7 @@ T}:T{
connection connection
.sp .sp
T}:T{ T}:T{
Emitted when a new connection is made\. connection is an instance of node\.tcp\.Connection\. Emitted when a new connection is made\. connection is an instance of tcp\.Connection\.
.sp .sp
T} T}
T{ T{
@ -1428,7 +1430,7 @@ Emitted when the server closes\. errorno is an integer which indicates what, if
T} T}
.TE .TE
.PP .PP
node\.tcp\.createServer(connection_listener); tcp\.createServer(connection_listener);
.RS 4 .RS 4
Creates a new TCP server\. Creates a new TCP server\.
.sp .sp
@ -1471,9 +1473,9 @@ event\.
.nr an-no-space-flag 1 .nr an-no-space-flag 1
.nr an-break-flag 1 .nr an-break-flag 1
.br .br
node.tcp.Connection tcp.Connection
.RS .RS
This object is used as a TCP client and also as a server\-side socket for node\.tcp\.Server\. This object is used as a TCP client and also as a server\-side socket for tcp\.Server\.
.sp .sp
.TS .TS
allbox tab(:); allbox tab(:);
@ -1540,7 +1542,7 @@ Emitted once the connection is fully closed\. The argument had_error is a boolea
T} T}
.TE .TE
.PP .PP
node\.tcp\.createConnection(port, host="127\.0\.0\.1") tcp\.createConnection(port, host="127\.0\.0\.1")
.RS 4 .RS 4
Creates a new connection object and opens a connection to the specified Creates a new connection object and opens a connection to the specified
port port
@ -1635,7 +1637,7 @@ connection\.setTimeout(timeout)
Sets the connection to timeout after Sets the connection to timeout after
timeout timeout
milliseconds of inactivity on the connection\. By default all milliseconds of inactivity on the connection\. By default all
node\.tcp\.Connection tcp\.Connection
objects have a timeout of 60 seconds (60000 ms)\. objects have a timeout of 60 seconds (60000 ms)\.
.sp .sp
If If

12
lib/tcp.js

@ -0,0 +1,12 @@
exports.createServer = function (on_connection, options) {
var server = new node.tcp.Server();
server.addListener("connection", on_connection);
//server.setOptions(options);
return server;
};
exports.createConnection = function (port, host) {
var connection = new node.tcp.Connection();
connection.connect(port, host);
return connection;
};

11
src/node.js

@ -1,8 +1,5 @@
node.tcp.createServer = function (on_connection, options) { node.tcp.createServer = function () {
var server = new node.tcp.Server(); throw new Error("node.tcp.createServer() has moved. Use require('/tcp.js') to access it.");
server.addListener("connection", on_connection);
//server.setOptions(options);
return server;
}; };
node.createProcess = function () { node.createProcess = function () {
@ -28,9 +25,7 @@ node.http.createClient = function () {
} }
node.tcp.createConnection = function (port, host) { node.tcp.createConnection = function (port, host) {
var connection = new node.tcp.Connection(); throw new Error("node.tcp.createConnection() has moved. Use require('/tcp.js') to access it.");
connection.connect(port, host);
return connection;
}; };
// Timers // Timers

3
test/mjsunit/test-http-malformed-request.js

@ -1,4 +1,5 @@
include("common.js"); include("common.js");
tcp = require("/tcp.js");
http = require("/http.js"); http = require("/http.js");
// Make sure no exceptions are thrown when receiving malformed HTTP // Make sure no exceptions are thrown when receiving malformed HTTP
@ -19,7 +20,7 @@ var s = http.createServer(function (req, res) {
}); });
s.listen(port); s.listen(port);
var c = node.tcp.createConnection(port); var c = tcp.createConnection(port);
c.addListener("connect", function () { c.addListener("connect", function () {
c.send("GET /hello?foo=%99bar HTTP/1.1\r\n\r\n"); c.send("GET /hello?foo=%99bar HTTP/1.1\r\n\r\n");
c.close(); c.close();

3
test/mjsunit/test-http-server.js

@ -1,4 +1,5 @@
include("common.js"); include("common.js");
tcp = require("/tcp.js");
http = require("/http.js"); http = require("/http.js");
var port = 8222; var port = 8222;
@ -32,7 +33,7 @@ http.createServer(function (req, res) {
}).listen(port); }).listen(port);
var c = node.tcp.createConnection(port); var c = tcp.createConnection(port);
c.setEncoding("utf8"); c.setEncoding("utf8");

5
test/mjsunit/test-tcp-binary.js

@ -1,4 +1,5 @@
include("common.js"); include("common.js");
tcp = require("/tcp.js");
PORT = 23123; PORT = 23123;
binaryString = ""; binaryString = "";
@ -18,7 +19,7 @@ for (var i = 255; i >= 0; i--) {
binaryString += S; binaryString += S;
} }
var echoServer = node.tcp.createServer(function (connection) { var echoServer = tcp.createServer(function (connection) {
connection.setEncoding("binary"); connection.setEncoding("binary");
connection.addListener("receive", function (chunk) { connection.addListener("receive", function (chunk) {
error("recved: " + JSON.stringify(chunk)); error("recved: " + JSON.stringify(chunk));
@ -33,7 +34,7 @@ echoServer.listen(PORT);
var recv = ""; var recv = "";
var j = 0; var j = 0;
var c = node.tcp.createConnection(PORT); var c = tcp.createConnection(PORT);
c.setEncoding("binary"); c.setEncoding("binary");
c.addListener("receive", function (chunk) { c.addListener("receive", function (chunk) {

5
test/mjsunit/test-tcp-many-clients.js

@ -1,4 +1,5 @@
include("common.js"); include("common.js");
tcp = require("/tcp.js");
// settings // settings
var port = 20743; var port = 20743;
var bytes = 1024*40; var bytes = 1024*40;
@ -13,7 +14,7 @@ for (var i = 0; i < bytes; i++) {
body += "C"; body += "C";
} }
var server = node.tcp.createServer(function (c) { var server = tcp.createServer(function (c) {
c.addListener("connect", function () { c.addListener("connect", function () {
total_connections++; total_connections++;
print("#"); print("#");
@ -24,7 +25,7 @@ var server = node.tcp.createServer(function (c) {
server.listen(port); server.listen(port);
function runClient (callback) { function runClient (callback) {
var client = node.tcp.createConnection(port); var client = tcp.createConnection(port);
client.connections = 0; client.connections = 0;
client.setEncoding("utf8"); client.setEncoding("utf8");

5
test/mjsunit/test-tcp-pingpong-delay.js

@ -1,4 +1,5 @@
include("common.js"); include("common.js");
tcp = require("/tcp.js");
var tests_run = 0; var tests_run = 0;
@ -9,7 +10,7 @@ function pingPongTest (port, host, on_complete) {
var count = 0; var count = 0;
var client_closed = false; var client_closed = false;
var server = node.tcp.createServer(function (socket) { var server = tcp.createServer(function (socket) {
socket.setEncoding("utf8"); socket.setEncoding("utf8");
socket.addListener("receive", function (data) { socket.addListener("receive", function (data) {
@ -43,7 +44,7 @@ function pingPongTest (port, host, on_complete) {
}); });
server.listen(port, host); server.listen(port, host);
var client = node.tcp.createConnection(port, host); var client = tcp.createConnection(port, host);
client.setEncoding("utf8"); client.setEncoding("utf8");

5
test/mjsunit/test-tcp-pingpong.js

@ -1,4 +1,5 @@
include("common.js"); include("common.js");
tcp = require("/tcp.js");
var tests_run = 0; var tests_run = 0;
@ -8,7 +9,7 @@ function pingPongTest (port, host, on_complete) {
var count = 0; var count = 0;
var sent_final_ping = false; var sent_final_ping = false;
var server = node.tcp.createServer(function (socket) { var server = tcp.createServer(function (socket) {
assertTrue(socket.remoteAddress !== null); assertTrue(socket.remoteAddress !== null);
assertTrue(socket.remoteAddress !== undefined); assertTrue(socket.remoteAddress !== undefined);
if (host === "127.0.0.1") if (host === "127.0.0.1")
@ -42,7 +43,7 @@ function pingPongTest (port, host, on_complete) {
}); });
server.listen(port, host); server.listen(port, host);
var client = node.tcp.createConnection(port, host); var client = tcp.createConnection(port, host);
client.setEncoding("utf8"); client.setEncoding("utf8");

5
test/mjsunit/test-tcp-reconnect.js

@ -1,4 +1,5 @@
include("common.js"); include("common.js");
tcp = require("/tcp.js");
var N = 50; var N = 50;
var port = 8921; var port = 8921;
@ -6,7 +7,7 @@ var c = 0;
var client_recv_count = 0; var client_recv_count = 0;
var disconnect_count = 0; var disconnect_count = 0;
var server = node.tcp.createServer(function (socket) { var server = tcp.createServer(function (socket) {
socket.addListener("connect", function () { socket.addListener("connect", function () {
socket.send("hello\r\n"); socket.send("hello\r\n");
}); });
@ -22,7 +23,7 @@ var server = node.tcp.createServer(function (socket) {
}); });
server.listen(port); server.listen(port);
var client = node.tcp.createConnection(port); var client = tcp.createConnection(port);
client.setEncoding("UTF8"); client.setEncoding("UTF8");

5
test/mjsunit/test-tcp-throttle-kernel-buffer.js

@ -1,4 +1,5 @@
include("common.js"); include("common.js");
tcp = require("/tcp.js");
PORT = 20444; PORT = 20444;
N = 30*1024; // 500kb N = 30*1024; // 500kb
@ -10,7 +11,7 @@ for (var i = 0; i < N; i++) {
puts("start server on port " + PORT); puts("start server on port " + PORT);
server = node.tcp.createServer(function (connection) { server = tcp.createServer(function (connection) {
connection.addListener("connect", function () { connection.addListener("connect", function () {
connection.send(body); connection.send(body);
connection.close(); connection.close();
@ -24,7 +25,7 @@ npauses = 0;
var paused = false; var paused = false;
client = node.tcp.createConnection(PORT); client = tcp.createConnection(PORT);
client.setEncoding("ascii"); client.setEncoding("ascii");
client.addListener("receive", function (d) { client.addListener("receive", function (d) {
chars_recved += d.length; chars_recved += d.length;

5
test/mjsunit/test-tcp-throttle.js

@ -1,8 +1,9 @@
include("common.js"); include("common.js");
tcp = require("/tcp.js");
PORT = 20443; PORT = 20443;
N = 200; N = 200;
server = node.tcp.createServer(function (connection) { server = tcp.createServer(function (connection) {
function send (j) { function send (j) {
if (j >= N) { if (j >= N) {
connection.close(); connection.close();
@ -21,7 +22,7 @@ server.listen(PORT);
recv = ""; recv = "";
chars_recved = 0; chars_recved = 0;
client = node.tcp.createConnection(PORT); client = tcp.createConnection(PORT);
client.setEncoding("ascii"); client.setEncoding("ascii");
client.addListener("receive", function (d) { client.addListener("receive", function (d) {
print(d); print(d);

5
test/mjsunit/test-tcp-timeout.js

@ -1,11 +1,12 @@
include("common.js"); include("common.js");
tcp = require("/tcp.js");
port = 9992; port = 9992;
exchanges = 0; exchanges = 0;
starttime = null; starttime = null;
timeouttime = null; timeouttime = null;
timeout = 1000; timeout = 1000;
var echo_server = node.tcp.createServer(function (socket) { var echo_server = tcp.createServer(function (socket) {
socket.setTimeout(timeout); socket.setTimeout(timeout);
socket.addListener("timeout", function (d) { socket.addListener("timeout", function (d) {
@ -27,7 +28,7 @@ var echo_server = node.tcp.createServer(function (socket) {
echo_server.listen(port); echo_server.listen(port);
puts("server listening at " + port); puts("server listening at " + port);
var client = node.tcp.createConnection(port); var client = tcp.createConnection(port);
client.setEncoding("UTF8"); client.setEncoding("UTF8");
client.setTimeout(0); // disable the timeout for client client.setTimeout(0); // disable the timeout for client
client.addListener("connect", function () { client.addListener("connect", function () {

Loading…
Cancel
Save