From 23cf502db779e57483410092a991a774b30edc66 Mon Sep 17 00:00:00 2001 From: Ryan Dahl Date: Tue, 16 Feb 2010 13:15:30 -0800 Subject: [PATCH] API: connection.send() renamed to connection.write() --- doc/api.txt | 10 +++++----- doc/index.html | 6 +++--- lib/http.js | 2 +- src/node_net.cc | 13 ++++++++++++- src/node_net.h | 3 ++- test/mjsunit/test-http-1.0.js | 2 +- test/mjsunit/test-http-malformed-request.js | 2 +- test/mjsunit/test-http-server.js | 8 ++++---- test/mjsunit/test-http-wget.js | 2 +- test/mjsunit/test-tcp-binary.js | 8 ++++---- test/mjsunit/test-tcp-many-clients.js | 2 +- test/mjsunit/test-tcp-pingpong-delay.js | 6 +++--- test/mjsunit/test-tcp-pingpong.js | 8 ++++---- test/mjsunit/test-tcp-reconnect.js | 2 +- test/mjsunit/test-tcp-throttle-kernel-buffer.js | 2 +- test/mjsunit/test-tcp-throttle.js | 8 ++++---- test/mjsunit/test-tcp-timeout.js | 8 ++++---- test/mjsunit/test-tcp-tls.js | 8 ++++---- 18 files changed, 56 insertions(+), 44 deletions(-) diff --git a/doc/api.txt b/doc/api.txt index b99670d45a9..8a3d272c7ef 100644 --- a/doc/api.txt +++ b/doc/api.txt @@ -1351,13 +1351,13 @@ var tcp = require("tcp"); var server = tcp.createServer(function (socket) { socket.setEncoding("utf8"); socket.addListener("connect", function () { - socket.send("hello\r\n"); + socket.write("hello\r\n"); }); socket.addListener("data", function (data) { - socket.send(data); + socket.write(data); }); socket.addListener("end", function () { - socket.send("goodbye\r\n"); + socket.write("goodbye\r\n"); socket.close(); }); }); @@ -1474,7 +1474,7 @@ Either +"closed"+, +"open"+, +"opening"+, +"readOnly"+, or +"writeOnly"+. +connection.setEncoding(encoding)+:: Sets the encoding (either +"ascii"+, +"utf8"+, or +"binary"+) for data that is received. -+connection.send(data, encoding="ascii")+:: ++connection.write(data, encoding="ascii")+:: Sends data on the connection. The second parameter specifies the encoding in the case of a string--it defaults to ASCII because encoding to UTF8 is rather slow. @@ -1507,7 +1507,7 @@ If +timeout+ is 0, then the idle timeout is disabled. +connection.setNoDelay(noDelay=true)+:: Disables the Nagle algorithm. By default TCP connections use the Nagle algorithm, they buffer data before sending it off. Setting +noDelay+ will -immediately fire off data each time +connection.send()+ is called. +immediately fire off data each time +connection.write()+ is called. +connection.verifyPeer()+:: Returns an integer indicating the trusted status of the peer in a TLS diff --git a/doc/index.html b/doc/index.html index afbabfc0f18..04945cab1ea 100644 --- a/doc/index.html +++ b/doc/index.html @@ -74,13 +74,13 @@ var server = tcp.createServer(function (socket) { socket.setEncoding("utf8"); socket.addListener("connect", function () { - socket.send("hello\r\n"); + socket.write("hello\r\n"); }); socket.addListener("receive", function (data) { - socket.send(data); + socket.write(data); }); socket.addListener("eof", function () { - socket.send("goodbye\r\n"); + socket.write("goodbye\r\n"); socket.close(); }); }); diff --git a/lib/http.js b/lib/http.js index d455506f28a..4260984fccf 100644 --- a/lib/http.js +++ b/lib/http.js @@ -357,7 +357,7 @@ function flushMessageQueue (connection, queue) { var data = message.output.shift(); var encoding = message.outputEncodings.shift(); - connection.send(data, encoding); + connection.write(data, encoding); } if (!message.finished) break; diff --git a/src/node_net.cc b/src/node_net.cc index 44eded0d697..d5f5ff699bd 100644 --- a/src/node_net.cc +++ b/src/node_net.cc @@ -96,6 +96,7 @@ void Connection::Initialize(v8::Handle target) { NODE_SET_PROTOTYPE_METHOD(constructor_template, "connect", Connect); NODE_SET_PROTOTYPE_METHOD(constructor_template, "send", Send); + NODE_SET_PROTOTYPE_METHOD(constructor_template, "write", Write); NODE_SET_PROTOTYPE_METHOD(constructor_template, "close", Close); NODE_SET_PROTOTYPE_METHOD(constructor_template, "forceClose", ForceClose); NODE_SET_PROTOTYPE_METHOD(constructor_template, "setEncoding", SetEncoding); @@ -586,7 +587,17 @@ Handle Connection::SetNoDelay(const Arguments& args) { return Undefined(); } + Handle Connection::Send(const Arguments& args) { + HandleScope scope; + return ThrowException(Exception::Error(String::New( + "connection.send() has been renamed to connection.write(). " + "(Also the 'receive' event has been renamed to 'data' and " + "the 'eof' event has been renamed to 'end'.)"))); +} + + +Handle Connection::Write(const Arguments& args) { HandleScope scope; Connection *connection = ObjectWrap::Unwrap(args.Holder()); assert(connection); @@ -609,7 +620,7 @@ Handle Connection::Send(const Arguments& args) { char * buf = new char[len]; ssize_t written = DecodeWrite(buf, len, args[0], enc); assert(written == len); - connection->Send(buf, written); + connection->Write(buf, written); delete [] buf; return scope.Close(Integer::New(written)); diff --git a/src/node_net.h b/src/node_net.h index 7ef6d4cd843..35efe4160ab 100644 --- a/src/node_net.h +++ b/src/node_net.h @@ -27,6 +27,7 @@ class Connection : public EventEmitter { static v8::Handle New(const v8::Arguments& args); static v8::Handle Connect(const v8::Arguments& args); static v8::Handle Send(const v8::Arguments& args); + static v8::Handle Write(const v8::Arguments& args); static v8::Handle SendUtf8(const v8::Arguments& args); static v8::Handle Close(const v8::Arguments& args); static v8::Handle ForceClose(const v8::Arguments& args); @@ -61,7 +62,7 @@ class Connection : public EventEmitter { return evcom_stream_connect(&stream_, address); } - void Send(const char *buf, size_t len) { + void Write(const char *buf, size_t len) { evcom_stream_write(&stream_, buf, len); } diff --git a/test/mjsunit/test-http-1.0.js b/test/mjsunit/test-http-1.0.js index 9fc0a5d0aeb..0a90478e57d 100644 --- a/test/mjsunit/test-http-1.0.js +++ b/test/mjsunit/test-http-1.0.js @@ -20,7 +20,7 @@ var c = tcp.createConnection(port); c.setEncoding("utf8"); c.addListener("connect", function () { - c.send( "GET / HTTP/1.0\r\n\r\n" ); + c.write( "GET / HTTP/1.0\r\n\r\n" ); }); c.addListener("data", function (chunk) { diff --git a/test/mjsunit/test-http-malformed-request.js b/test/mjsunit/test-http-malformed-request.js index ae89df49391..160da460126 100644 --- a/test/mjsunit/test-http-malformed-request.js +++ b/test/mjsunit/test-http-malformed-request.js @@ -23,7 +23,7 @@ s.listen(port); var c = tcp.createConnection(port); c.addListener("connect", function () { - c.send("GET /hello?foo=%99bar HTTP/1.1\r\n\r\n"); + c.write("GET /hello?foo=%99bar HTTP/1.1\r\n\r\n"); c.close(); }); diff --git a/test/mjsunit/test-http-server.js b/test/mjsunit/test-http-server.js index 35b05f24095..0dec3adace0 100644 --- a/test/mjsunit/test-http-server.js +++ b/test/mjsunit/test-http-server.js @@ -50,7 +50,7 @@ var c = tcp.createConnection(port); c.setEncoding("utf8"); c.addListener("connect", function () { - c.send( "GET /hello?hello=world&foo=b==ar HTTP/1.1\r\n\r\n" ); + c.write( "GET /hello?hello=world&foo=b==ar HTTP/1.1\r\n\r\n" ); requests_sent += 1; }); @@ -58,13 +58,13 @@ c.addListener("data", function (chunk) { server_response += chunk; if (requests_sent == 1) { - c.send("POST /quit HTTP/1.1\r\n\r\n"); + c.write("POST /quit HTTP/1.1\r\n\r\n"); requests_sent += 1; } if (requests_sent == 2) { - c.send("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.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(); assert.equal(c.readyState, "readOnly"); requests_sent += 2; diff --git a/test/mjsunit/test-http-wget.js b/test/mjsunit/test-http-wget.js index 33c477f4522..e4c5b74adb0 100644 --- a/test/mjsunit/test-http-wget.js +++ b/test/mjsunit/test-http-wget.js @@ -36,7 +36,7 @@ var c = tcp.createConnection(port); c.setEncoding("utf8"); c.addListener("connect", function () { - c.send( "GET / HTTP/1.0\r\n" + + c.write("GET / HTTP/1.0\r\n" + "Connection: Keep-Alive\r\n\r\n"); }); diff --git a/test/mjsunit/test-tcp-binary.js b/test/mjsunit/test-tcp-binary.js index 5ce6b9af842..1bdc33ad669 100644 --- a/test/mjsunit/test-tcp-binary.js +++ b/test/mjsunit/test-tcp-binary.js @@ -23,7 +23,7 @@ var echoServer = tcp.createServer(function (connection) { connection.setEncoding("binary"); connection.addListener("data", function (chunk) { error("recved: " + JSON.stringify(chunk)); - connection.send(chunk, "binary"); + connection.write(chunk, "binary"); }); connection.addListener("end", function () { connection.close(); @@ -39,8 +39,8 @@ var c = tcp.createConnection(PORT); c.setEncoding("binary"); c.addListener("data", function (chunk) { if (j < 256) { - error("send " + j); - c.send(String.fromCharCode(j), "binary"); + error("write " + j); + c.write(String.fromCharCode(j), "binary"); j++; } else { c.close(); @@ -49,7 +49,7 @@ c.addListener("data", function (chunk) { }); c.addListener("connect", function () { - c.send(binaryString, "binary"); + c.write(binaryString, "binary"); }); c.addListener("close", function () { diff --git a/test/mjsunit/test-tcp-many-clients.js b/test/mjsunit/test-tcp-many-clients.js index 69fb1459f9f..5d229834d18 100644 --- a/test/mjsunit/test-tcp-many-clients.js +++ b/test/mjsunit/test-tcp-many-clients.js @@ -18,7 +18,7 @@ var server = tcp.createServer(function (c) { c.addListener("connect", function () { total_connections++; print("#"); - c.send(body); + c.write(body); c.close(); }); }); diff --git a/test/mjsunit/test-tcp-pingpong-delay.js b/test/mjsunit/test-tcp-pingpong-delay.js index d7d2bebcdb4..b8d2d064517 100644 --- a/test/mjsunit/test-tcp-pingpong-delay.js +++ b/test/mjsunit/test-tcp-pingpong-delay.js @@ -20,7 +20,7 @@ function pingPongTest (port, host, on_complete) { assert.equal(true, count <= N); setTimeout(function () { assert.equal("open", socket.readyState); - socket.send("PONG"); + socket.write("PONG"); }, DELAY); }); @@ -50,7 +50,7 @@ function pingPongTest (port, host, on_complete) { client.addListener("connect", function () { assert.equal("open", client.readyState); - client.send("PING"); + client.write("PING"); }); client.addListener("data", function (data) { @@ -61,7 +61,7 @@ function pingPongTest (port, host, on_complete) { setTimeout(function () { assert.equal("open", client.readyState); if (count++ < N) { - client.send("PING"); + client.write("PING"); } else { puts("closing client"); client.close(); diff --git a/test/mjsunit/test-tcp-pingpong.js b/test/mjsunit/test-tcp-pingpong.js index 543fcfe49b1..3f067be2fb2 100644 --- a/test/mjsunit/test-tcp-pingpong.js +++ b/test/mjsunit/test-tcp-pingpong.js @@ -26,7 +26,7 @@ function pingPongTest (port, host, on_complete) { assert.equal("open", socket.readyState); assert.equal(true, count <= N); if (/PING/.exec(data)) { - socket.send("PONG"); + socket.write("PONG"); } }); @@ -49,7 +49,7 @@ function pingPongTest (port, host, on_complete) { client.addListener("connect", function () { assert.equal("open", client.readyState); - client.send("PING"); + client.write("PING"); }); client.addListener("data", function (data) { @@ -64,10 +64,10 @@ function pingPongTest (port, host, on_complete) { } if (count < N) { - client.send("PING"); + client.write("PING"); } else { sent_final_ping = true; - client.send("PING"); + client.write("PING"); client.close(); } }); diff --git a/test/mjsunit/test-tcp-reconnect.js b/test/mjsunit/test-tcp-reconnect.js index 6d2a125f928..4bf4ed89454 100644 --- a/test/mjsunit/test-tcp-reconnect.js +++ b/test/mjsunit/test-tcp-reconnect.js @@ -9,7 +9,7 @@ var disconnect_count = 0; var server = tcp.createServer(function (socket) { socket.addListener("connect", function () { - socket.send("hello\r\n"); + socket.write("hello\r\n"); }); socket.addListener("end", function () { diff --git a/test/mjsunit/test-tcp-throttle-kernel-buffer.js b/test/mjsunit/test-tcp-throttle-kernel-buffer.js index 9c5960ee019..10fdcb4b798 100644 --- a/test/mjsunit/test-tcp-throttle-kernel-buffer.js +++ b/test/mjsunit/test-tcp-throttle-kernel-buffer.js @@ -13,7 +13,7 @@ puts("start server on port " + PORT); server = tcp.createServer(function (connection) { connection.addListener("connect", function () { - connection.send(body); + connection.write(body); connection.close(); }); }); diff --git a/test/mjsunit/test-tcp-throttle.js b/test/mjsunit/test-tcp-throttle.js index d85978b8d29..239d7ccea39 100644 --- a/test/mjsunit/test-tcp-throttle.js +++ b/test/mjsunit/test-tcp-throttle.js @@ -4,17 +4,17 @@ PORT = 20443; N = 200; server = tcp.createServer(function (connection) { - function send (j) { + function write (j) { if (j >= N) { connection.close(); return; } setTimeout(function () { - connection.send("C"); - send(j+1); + connection.write("C"); + write(j+1); }, 10); } - send(0); + write(0); }); server.listen(PORT); diff --git a/test/mjsunit/test-tcp-timeout.js b/test/mjsunit/test-tcp-timeout.js index d977cc773cf..b2f363d2da1 100644 --- a/test/mjsunit/test-tcp-timeout.js +++ b/test/mjsunit/test-tcp-timeout.js @@ -17,7 +17,7 @@ var echo_server = tcp.createServer(function (socket) { socket.addListener("data", function (d) { p(d); - socket.send(d); + socket.write(d); }); socket.addListener("end", function () { @@ -33,15 +33,15 @@ client.setEncoding("UTF8"); client.setTimeout(0); // disable the timeout for client client.addListener("connect", function () { puts("client connected."); - client.send("hello\r\n"); + client.write("hello\r\n"); }); client.addListener("data", function (chunk) { assert.equal("hello\r\n", chunk); if (exchanges++ < 5) { setTimeout(function () { - puts("client send 'hello'"); - client.send("hello\r\n"); + puts("client write 'hello'"); + client.write("hello\r\n"); }, 500); if (exchanges == 5) { diff --git a/test/mjsunit/test-tcp-tls.js b/test/mjsunit/test-tcp-tls.js index d8f7459c026..9a47d5af1db 100644 --- a/test/mjsunit/test-tcp-tls.js +++ b/test/mjsunit/test-tcp-tls.js @@ -31,7 +31,7 @@ function tlsTest (port, host, caPem, keyPem, certPem) { assert.equal("open", socket.readyState); assert.equal(true, count <= N); if (/PING/.exec(data)) { - socket.send("PONG"); + socket.write("PONG"); } }); @@ -62,7 +62,7 @@ function tlsTest (port, host, caPem, keyPem, certPem) { assert.equal(verified, 1); assert.equal(peerDN, "C=UK,ST=Acknack Ltd,L=Rhys Jones,O=node.js," + "OU=Test TLS Certificate,CN=localhost"); - client.send("PING"); + client.write("PING"); }); client.addListener("data", function (data) { @@ -79,10 +79,10 @@ function tlsTest (port, host, caPem, keyPem, certPem) { } if (count < N) { - client.send("PING"); + client.write("PING"); } else { sent_final_ping = true; - client.send("PING"); + client.write("PING"); client.close(); } });