No deprecation messages. Not sure how...
objects which emit events are instances of +events.EventEmitter+.
Events are represented by a camel-cased string. Here are some examples:
-+"connection"+, +"receive"+, +"messageBegin"+.
++"connection"+, +"data"+, +"messageBegin"+.
Functions can be then be attached to objects, to be executed when an event
is emitted. These functions are called _listeners_.
socket.addListener("connect", function () {
socket.send("hello\r\n");
});
- socket.addListener("receive", function (data) {
+ socket.addListener("data", function (data) {
socket.send(data);
});
- socket.addListener("eof", function () {
+ socket.addListener("end", function () {
socket.send("goodbye\r\n");
socket.close();
});
|+"connect"+ | | Call once the connection is established
after a call to +createConnection()+ or
+connect()+.
-|+"receive"+ | +data+ | Called when data is received on the
+|+"data"+ | +data+ | Called when data is received on the
connection. +data+ will be a string.
Encoding of data is set by
+connection.setEncoding()+.
-|+"eof"+ | | Called when the other end of the
+|+"end"+ | | Called when the other end of the
connection sends a FIN packet.
After this is emitted the +readyState+
will be +"writeOnly"+. One should probably
necessary in case of errors (parse error or so).
+connection.readPause()+::
-Pauses the reading of data. That is, +"receive"+ events will not be emitted.
+Pauses the reading of data. That is, +"data"+ events will not be emitted.
Useful to throttle back an upload.
+connection.readResume()+::
connection.resetParser();
// is this really needed?
- connection.addListener("eof", function () {
+ connection.addListener("end", function () {
if (responses.length == 0) {
connection.close();
} else {
currentRequest.flush();
});
- client.addListener("eof", function () {
- //sys.debug("client got eof closing. readyState = " + client.readyState);
+ client.addListener("end", function () {
+ //sys.debug("client got end closing. readyState = " + client.readyState);
client.close();
});
static Persistent<String> header_value_symbol;
static Persistent<String> header_complete_symbol;
static Persistent<String> body_symbol;
-static Persistent<String> eof_symbol;
+static Persistent<String> end_symbol;
static Persistent<String> delete_sym;
static Persistent<String> get_sym;
NODE_SET_PROTOTYPE_METHOD(server_constructor_template, "resetParser", ResetParser);
server_constructor_template->SetClassName(String::NewSymbol("ServerSideConnection"));
- eof_symbol = NODE_PSYMBOL("eof");
+ end_symbol = NODE_PSYMBOL("end");
}
assert(refs_);
size_t nparsed;
nparsed = http_parser_execute(&parser_, NULL, 0);
- Emit(eof_symbol, 0, NULL);
+ Emit(end_symbol, 0, NULL);
}
int
static Persistent<String> closing_symbol;
static Persistent<String> closed_symbol;
-static Persistent<String> receive_symbol;
+static Persistent<String> data_symbol;
static Persistent<String> connection_symbol;
static Persistent<String> connect_symbol;
static Persistent<String> timeout_symbol;
static Persistent<String> drain_symbol;
-static Persistent<String> eof_symbol;
+static Persistent<String> end_symbol;
static Persistent<String> close_symbol;
static const struct addrinfo server_tcp_hints =
closing_symbol = NODE_PSYMBOL("closing");
closed_symbol = NODE_PSYMBOL("closed");
- receive_symbol = NODE_PSYMBOL("receive");
+ data_symbol = NODE_PSYMBOL("data");
connection_symbol = NODE_PSYMBOL("connection");
connect_symbol = NODE_PSYMBOL("connect");
timeout_symbol = NODE_PSYMBOL("timeout");
drain_symbol = NODE_PSYMBOL("drain");
- eof_symbol = NODE_PSYMBOL("eof");
+ end_symbol = NODE_PSYMBOL("end");
close_symbol = NODE_PSYMBOL("close");
Local<FunctionTemplate> t = FunctionTemplate::New(New);
void Connection::OnReceive(const void *buf, size_t len) {
HandleScope scope;
Local<Value> data = Encode(buf, len, encoding_);
- Emit(receive_symbol, 1, &data);
+ Emit(data_symbol, 1, &data);
}
void Connection::OnClose() {
void Connection::OnEOF() {
HandleScope scope;
- Emit(eof_symbol, 0, NULL);
+ Emit(end_symbol, 0, NULL);
}
Persistent<FunctionTemplate> Server::constructor_template;
c.send( "GET / HTTP/1.0\r\n\r\n" );
});
-c.addListener("receive", function (chunk) {
+c.addListener("data", function (chunk) {
puts(chunk);
server_response += chunk;
});
-c.addListener("eof", function () {
+c.addListener("end", function () {
client_got_eof = true;
c.close();
server.close();
errorCount++;
});
-client.addListener("eof", function() {
+client.addListener("end", function() {
sys.puts("EOF!");
eofCount++;
});
requests_sent += 1;
});
-c.addListener("receive", function (chunk) {
+c.addListener("data", function (chunk) {
server_response += chunk;
if (requests_sent == 1) {
});
-c.addListener("eof", function () {
+c.addListener("end", function () {
client_got_eof = true;
});
"Connection: Keep-Alive\r\n\r\n");
});
-c.addListener("receive", function (chunk) {
+c.addListener("data", function (chunk) {
puts(chunk);
server_response += chunk;
});
-c.addListener("eof", function () {
+c.addListener("end", function () {
client_got_eof = true;
- puts('got eof');
+ puts('got end');
c.close();
});
child.close();
}
} else {
- puts('child eof');
+ puts('child end');
}
});
var echoServer = tcp.createServer(function (connection) {
connection.setEncoding("binary");
- connection.addListener("receive", function (chunk) {
+ connection.addListener("data", function (chunk) {
error("recved: " + JSON.stringify(chunk));
connection.send(chunk, "binary");
});
- connection.addListener("eof", function () {
+ connection.addListener("end", function () {
connection.close();
});
});
var c = tcp.createConnection(PORT);
c.setEncoding("binary");
-c.addListener("receive", function (chunk) {
+c.addListener("data", function (chunk) {
if (j < 256) {
error("send " + j);
c.send(String.fromCharCode(j), "binary");
client.connections += 1;
});
- client.addListener("receive", function (chunk) {
+ client.addListener("data", function (chunk) {
this.recved += chunk;
});
- client.addListener("eof", function (had_error) {
+ client.addListener("end", function (had_error) {
client.close();
});
var server = tcp.createServer(function (socket) {
socket.setEncoding("utf8");
- socket.addListener("receive", function (data) {
+ socket.addListener("data", function (data) {
puts(data);
assert.equal("PING", data);
assert.equal("open", socket.readyState);
assert.equal(false, true);
});
- socket.addListener("eof", function () {
+ socket.addListener("end", function () {
puts("server-side socket EOF");
assert.equal("writeOnly", socket.readyState);
socket.close();
client.send("PING");
});
- client.addListener("receive", function (data) {
+ client.addListener("data", function (data) {
puts(data);
assert.equal("PONG", data);
assert.equal("open", client.readyState);
socket.setNoDelay();
socket.timeout = 0;
- socket.addListener("receive", function (data) {
+ socket.addListener("data", function (data) {
puts("server got: " + JSON.stringify(data));
assert.equal("open", socket.readyState);
assert.equal(true, count <= N);
}
});
- socket.addListener("eof", function () {
+ socket.addListener("end", function () {
assert.equal("writeOnly", socket.readyState);
socket.close();
});
client.send("PING");
});
- client.addListener("receive", function (data) {
+ client.addListener("data", function (data) {
assert.equal("PONG", data);
count += 1;
socket.send("hello\r\n");
});
- socket.addListener("eof", function () {
+ socket.addListener("end", function () {
socket.close();
});
puts("client connected.");
});
-client.addListener("receive", function (chunk) {
+client.addListener("data", function (chunk) {
client_recv_count += 1;
puts("client_recv_count " + client_recv_count);
assert.equal("hello\r\n", chunk);
var paused = false;
client = tcp.createConnection(PORT);
client.setEncoding("ascii");
-client.addListener("receive", function (d) {
+client.addListener("data", function (d) {
chars_recved += d.length;
puts("got " + chars_recved);
if (!paused) {
}
});
-client.addListener("eof", function () {
+client.addListener("end", function () {
server.close();
client.close();
});
client = tcp.createConnection(PORT);
client.setEncoding("ascii");
-client.addListener("receive", function (d) {
+client.addListener("data", function (d) {
print(d);
recv += d;
});
}, 500);
-client.addListener("eof", function () {
+client.addListener("end", function () {
server.close();
client.close();
});
p(timeouttime);
});
- socket.addListener("receive", function (d) {
+ socket.addListener("data", function (d) {
p(d);
socket.send(d);
});
- socket.addListener("eof", function () {
+ socket.addListener("end", function () {
socket.close();
});
});
client.send("hello\r\n");
});
-client.addListener("receive", function (chunk) {
+client.addListener("data", function (chunk) {
assert.equal("hello\r\n", chunk);
if (exchanges++ < 5) {
setTimeout(function () {
assert.equal(false, true);
});
-client.addListener("eof", function () {
- puts("client eof");
+client.addListener("end", function () {
+ puts("client end");
client.close();
});
socket.setNoDelay();
socket.timeout = 0;
- socket.addListener("receive", function (data) {
+ socket.addListener("data", function (data) {
var verified = socket.verifyPeer();
var peerDN = socket.getPeerCertificate("DNstring");
assert.equal(verified, 1);
}
});
- socket.addListener("eof", function () {
+ socket.addListener("end", function () {
assert.equal("writeOnly", socket.readyState);
socket.close();
});
client.send("PING");
});
- client.addListener("receive", function (data) {
+ client.addListener("data", function (data) {
assert.equal("PONG", data);
count += 1;