Browse Source

API: connection.send() renamed to connection.write()

v0.7.4-release
Ryan Dahl 15 years ago
parent
commit
23cf502db7
  1. 10
      doc/api.txt
  2. 6
      doc/index.html
  3. 2
      lib/http.js
  4. 13
      src/node_net.cc
  5. 3
      src/node_net.h
  6. 2
      test/mjsunit/test-http-1.0.js
  7. 2
      test/mjsunit/test-http-malformed-request.js
  8. 8
      test/mjsunit/test-http-server.js
  9. 2
      test/mjsunit/test-http-wget.js
  10. 8
      test/mjsunit/test-tcp-binary.js
  11. 2
      test/mjsunit/test-tcp-many-clients.js
  12. 6
      test/mjsunit/test-tcp-pingpong-delay.js
  13. 8
      test/mjsunit/test-tcp-pingpong.js
  14. 2
      test/mjsunit/test-tcp-reconnect.js
  15. 2
      test/mjsunit/test-tcp-throttle-kernel-buffer.js
  16. 8
      test/mjsunit/test-tcp-throttle.js
  17. 8
      test/mjsunit/test-tcp-timeout.js
  18. 8
      test/mjsunit/test-tcp-tls.js

10
doc/api.txt

@ -1351,13 +1351,13 @@ var tcp = require("tcp");
var server = tcp.createServer(function (socket) { var server = tcp.createServer(function (socket) {
socket.setEncoding("utf8"); socket.setEncoding("utf8");
socket.addListener("connect", function () { socket.addListener("connect", function () {
socket.send("hello\r\n"); socket.write("hello\r\n");
}); });
socket.addListener("data", function (data) { socket.addListener("data", function (data) {
socket.send(data); socket.write(data);
}); });
socket.addListener("end", function () { socket.addListener("end", function () {
socket.send("goodbye\r\n"); socket.write("goodbye\r\n");
socket.close(); socket.close();
}); });
}); });
@ -1474,7 +1474,7 @@ Either +"closed"+, +"open"+, +"opening"+, +"readOnly"+, or +"writeOnly"+.
+connection.setEncoding(encoding)+:: +connection.setEncoding(encoding)+::
Sets the encoding (either +"ascii"+, +"utf8"+, or +"binary"+) for data that is received. 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 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 in the case of a string--it defaults to ASCII because encoding to UTF8 is
rather slow. rather slow.
@ -1507,7 +1507,7 @@ If +timeout+ is 0, then the idle timeout is disabled.
+connection.setNoDelay(noDelay=true)+:: +connection.setNoDelay(noDelay=true)+::
Disables the Nagle algorithm. By default TCP connections use the Nagle Disables the Nagle algorithm. By default TCP connections use the Nagle
algorithm, they buffer data before sending it off. Setting +noDelay+ will 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()+:: +connection.verifyPeer()+::
Returns an integer indicating the trusted status of the peer in a TLS Returns an integer indicating the trusted status of the peer in a TLS

6
doc/index.html

@ -74,13 +74,13 @@ var tcp = require('tcp');
var server = tcp.createServer(function (socket) { var server = tcp.createServer(function (socket) {
socket.setEncoding("utf8"); socket.setEncoding("utf8");
socket.addListener("connect", function () { socket.addListener("connect", function () {
socket.send("hello\r\n"); socket.write("hello\r\n");
}); });
socket.addListener("receive", function (data) { socket.addListener("receive", function (data) {
socket.send(data); socket.write(data);
}); });
socket.addListener("eof", function () { socket.addListener("eof", function () {
socket.send("goodbye\r\n"); socket.write("goodbye\r\n");
socket.close(); socket.close();
}); });
}); });

2
lib/http.js

@ -357,7 +357,7 @@ function flushMessageQueue (connection, queue) {
var data = message.output.shift(); var data = message.output.shift();
var encoding = message.outputEncodings.shift(); var encoding = message.outputEncodings.shift();
connection.send(data, encoding); connection.write(data, encoding);
} }
if (!message.finished) break; if (!message.finished) break;

13
src/node_net.cc

@ -96,6 +96,7 @@ void Connection::Initialize(v8::Handle<v8::Object> target) {
NODE_SET_PROTOTYPE_METHOD(constructor_template, "connect", Connect); NODE_SET_PROTOTYPE_METHOD(constructor_template, "connect", Connect);
NODE_SET_PROTOTYPE_METHOD(constructor_template, "send", Send); 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, "close", Close);
NODE_SET_PROTOTYPE_METHOD(constructor_template, "forceClose", ForceClose); NODE_SET_PROTOTYPE_METHOD(constructor_template, "forceClose", ForceClose);
NODE_SET_PROTOTYPE_METHOD(constructor_template, "setEncoding", SetEncoding); NODE_SET_PROTOTYPE_METHOD(constructor_template, "setEncoding", SetEncoding);
@ -586,7 +587,17 @@ Handle<Value> Connection::SetNoDelay(const Arguments& args) {
return Undefined(); return Undefined();
} }
Handle<Value> Connection::Send(const Arguments& args) { Handle<Value> 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<Value> Connection::Write(const Arguments& args) {
HandleScope scope; HandleScope scope;
Connection *connection = ObjectWrap::Unwrap<Connection>(args.Holder()); Connection *connection = ObjectWrap::Unwrap<Connection>(args.Holder());
assert(connection); assert(connection);
@ -609,7 +620,7 @@ Handle<Value> Connection::Send(const Arguments& args) {
char * buf = new char[len]; char * buf = new char[len];
ssize_t written = DecodeWrite(buf, len, args[0], enc); ssize_t written = DecodeWrite(buf, len, args[0], enc);
assert(written == len); assert(written == len);
connection->Send(buf, written); connection->Write(buf, written);
delete [] buf; delete [] buf;
return scope.Close(Integer::New(written)); return scope.Close(Integer::New(written));

3
src/node_net.h

@ -27,6 +27,7 @@ class Connection : public EventEmitter {
static v8::Handle<v8::Value> New(const v8::Arguments& args); static v8::Handle<v8::Value> New(const v8::Arguments& args);
static v8::Handle<v8::Value> Connect(const v8::Arguments& args); static v8::Handle<v8::Value> Connect(const v8::Arguments& args);
static v8::Handle<v8::Value> Send(const v8::Arguments& args); static v8::Handle<v8::Value> Send(const v8::Arguments& args);
static v8::Handle<v8::Value> Write(const v8::Arguments& args);
static v8::Handle<v8::Value> SendUtf8(const v8::Arguments& args); static v8::Handle<v8::Value> SendUtf8(const v8::Arguments& args);
static v8::Handle<v8::Value> Close(const v8::Arguments& args); static v8::Handle<v8::Value> Close(const v8::Arguments& args);
static v8::Handle<v8::Value> ForceClose(const v8::Arguments& args); static v8::Handle<v8::Value> ForceClose(const v8::Arguments& args);
@ -61,7 +62,7 @@ class Connection : public EventEmitter {
return evcom_stream_connect(&stream_, address); 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); evcom_stream_write(&stream_, buf, len);
} }

2
test/mjsunit/test-http-1.0.js

@ -20,7 +20,7 @@ var c = tcp.createConnection(port);
c.setEncoding("utf8"); c.setEncoding("utf8");
c.addListener("connect", function () { 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) { c.addListener("data", function (chunk) {

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

@ -23,7 +23,7 @@ s.listen(port);
var c = 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.write("GET /hello?foo=%99bar HTTP/1.1\r\n\r\n");
c.close(); c.close();
}); });

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

@ -50,7 +50,7 @@ var c = tcp.createConnection(port);
c.setEncoding("utf8"); c.setEncoding("utf8");
c.addListener("connect", function () { 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; requests_sent += 1;
}); });
@ -58,13 +58,13 @@ c.addListener("data", function (chunk) {
server_response += chunk; server_response += chunk;
if (requests_sent == 1) { 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; requests_sent += 1;
} }
if (requests_sent == 2) { if (requests_sent == 2) {
c.send("GET / HTTP/1.1\r\nX-X: foo\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"); +"GET / HTTP/1.1\r\nX-X: bar\r\n\r\n");
c.close(); c.close();
assert.equal(c.readyState, "readOnly"); assert.equal(c.readyState, "readOnly");
requests_sent += 2; requests_sent += 2;

2
test/mjsunit/test-http-wget.js

@ -36,7 +36,7 @@ var c = tcp.createConnection(port);
c.setEncoding("utf8"); c.setEncoding("utf8");
c.addListener("connect", function () { 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"); "Connection: Keep-Alive\r\n\r\n");
}); });

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

@ -23,7 +23,7 @@ var echoServer = tcp.createServer(function (connection) {
connection.setEncoding("binary"); connection.setEncoding("binary");
connection.addListener("data", function (chunk) { connection.addListener("data", function (chunk) {
error("recved: " + JSON.stringify(chunk)); error("recved: " + JSON.stringify(chunk));
connection.send(chunk, "binary"); connection.write(chunk, "binary");
}); });
connection.addListener("end", function () { connection.addListener("end", function () {
connection.close(); connection.close();
@ -39,8 +39,8 @@ var c = tcp.createConnection(PORT);
c.setEncoding("binary"); c.setEncoding("binary");
c.addListener("data", function (chunk) { c.addListener("data", function (chunk) {
if (j < 256) { if (j < 256) {
error("send " + j); error("write " + j);
c.send(String.fromCharCode(j), "binary"); c.write(String.fromCharCode(j), "binary");
j++; j++;
} else { } else {
c.close(); c.close();
@ -49,7 +49,7 @@ c.addListener("data", function (chunk) {
}); });
c.addListener("connect", function () { c.addListener("connect", function () {
c.send(binaryString, "binary"); c.write(binaryString, "binary");
}); });
c.addListener("close", function () { c.addListener("close", function () {

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

@ -18,7 +18,7 @@ var server = tcp.createServer(function (c) {
c.addListener("connect", function () { c.addListener("connect", function () {
total_connections++; total_connections++;
print("#"); print("#");
c.send(body); c.write(body);
c.close(); c.close();
}); });
}); });

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

@ -20,7 +20,7 @@ function pingPongTest (port, host, on_complete) {
assert.equal(true, count <= N); assert.equal(true, count <= N);
setTimeout(function () { setTimeout(function () {
assert.equal("open", socket.readyState); assert.equal("open", socket.readyState);
socket.send("PONG"); socket.write("PONG");
}, DELAY); }, DELAY);
}); });
@ -50,7 +50,7 @@ function pingPongTest (port, host, on_complete) {
client.addListener("connect", function () { client.addListener("connect", function () {
assert.equal("open", client.readyState); assert.equal("open", client.readyState);
client.send("PING"); client.write("PING");
}); });
client.addListener("data", function (data) { client.addListener("data", function (data) {
@ -61,7 +61,7 @@ function pingPongTest (port, host, on_complete) {
setTimeout(function () { setTimeout(function () {
assert.equal("open", client.readyState); assert.equal("open", client.readyState);
if (count++ < N) { if (count++ < N) {
client.send("PING"); client.write("PING");
} else { } else {
puts("closing client"); puts("closing client");
client.close(); client.close();

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

@ -26,7 +26,7 @@ function pingPongTest (port, host, on_complete) {
assert.equal("open", socket.readyState); assert.equal("open", socket.readyState);
assert.equal(true, count <= N); assert.equal(true, count <= N);
if (/PING/.exec(data)) { if (/PING/.exec(data)) {
socket.send("PONG"); socket.write("PONG");
} }
}); });
@ -49,7 +49,7 @@ function pingPongTest (port, host, on_complete) {
client.addListener("connect", function () { client.addListener("connect", function () {
assert.equal("open", client.readyState); assert.equal("open", client.readyState);
client.send("PING"); client.write("PING");
}); });
client.addListener("data", function (data) { client.addListener("data", function (data) {
@ -64,10 +64,10 @@ function pingPongTest (port, host, on_complete) {
} }
if (count < N) { if (count < N) {
client.send("PING"); client.write("PING");
} else { } else {
sent_final_ping = true; sent_final_ping = true;
client.send("PING"); client.write("PING");
client.close(); client.close();
} }
}); });

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

@ -9,7 +9,7 @@ var disconnect_count = 0;
var server = tcp.createServer(function (socket) { var server = tcp.createServer(function (socket) {
socket.addListener("connect", function () { socket.addListener("connect", function () {
socket.send("hello\r\n"); socket.write("hello\r\n");
}); });
socket.addListener("end", function () { socket.addListener("end", function () {

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

@ -13,7 +13,7 @@ puts("start server on port " + PORT);
server = tcp.createServer(function (connection) { server = tcp.createServer(function (connection) {
connection.addListener("connect", function () { connection.addListener("connect", function () {
connection.send(body); connection.write(body);
connection.close(); connection.close();
}); });
}); });

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

@ -4,17 +4,17 @@ PORT = 20443;
N = 200; N = 200;
server = tcp.createServer(function (connection) { server = tcp.createServer(function (connection) {
function send (j) { function write (j) {
if (j >= N) { if (j >= N) {
connection.close(); connection.close();
return; return;
} }
setTimeout(function () { setTimeout(function () {
connection.send("C"); connection.write("C");
send(j+1); write(j+1);
}, 10); }, 10);
} }
send(0); write(0);
}); });
server.listen(PORT); server.listen(PORT);

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

@ -17,7 +17,7 @@ var echo_server = tcp.createServer(function (socket) {
socket.addListener("data", function (d) { socket.addListener("data", function (d) {
p(d); p(d);
socket.send(d); socket.write(d);
}); });
socket.addListener("end", function () { socket.addListener("end", function () {
@ -33,15 +33,15 @@ 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 () {
puts("client connected."); puts("client connected.");
client.send("hello\r\n"); client.write("hello\r\n");
}); });
client.addListener("data", function (chunk) { client.addListener("data", function (chunk) {
assert.equal("hello\r\n", chunk); assert.equal("hello\r\n", chunk);
if (exchanges++ < 5) { if (exchanges++ < 5) {
setTimeout(function () { setTimeout(function () {
puts("client send 'hello'"); puts("client write 'hello'");
client.send("hello\r\n"); client.write("hello\r\n");
}, 500); }, 500);
if (exchanges == 5) { if (exchanges == 5) {

8
test/mjsunit/test-tcp-tls.js

@ -31,7 +31,7 @@ function tlsTest (port, host, caPem, keyPem, certPem) {
assert.equal("open", socket.readyState); assert.equal("open", socket.readyState);
assert.equal(true, count <= N); assert.equal(true, count <= N);
if (/PING/.exec(data)) { 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(verified, 1);
assert.equal(peerDN, "C=UK,ST=Acknack Ltd,L=Rhys Jones,O=node.js," assert.equal(peerDN, "C=UK,ST=Acknack Ltd,L=Rhys Jones,O=node.js,"
+ "OU=Test TLS Certificate,CN=localhost"); + "OU=Test TLS Certificate,CN=localhost");
client.send("PING"); client.write("PING");
}); });
client.addListener("data", function (data) { client.addListener("data", function (data) {
@ -79,10 +79,10 @@ function tlsTest (port, host, caPem, keyPem, certPem) {
} }
if (count < N) { if (count < N) {
client.send("PING"); client.write("PING");
} else { } else {
sent_final_ping = true; sent_final_ping = true;
client.send("PING"); client.write("PING");
client.close(); client.close();
} }
}); });

Loading…
Cancel
Save