Browse Source

Timer clean ups

Also bugfix getting pointer to C++ class in watcher
v0.7.4-release
Ryan Dahl 15 years ago
parent
commit
a01d8a0d68
  1. 5
      src/node_timer.cc
  2. 1
      src/node_timer.h
  3. 13
      test/pummel/test-tcp-timeout.js

5
src/node_timer.cc

@ -114,14 +114,15 @@ Timer::Start (const Arguments& args)
if (args.Length() != 2)
return ThrowException(String::New("Bad arguments"));
bool was_active = ev_is_active(&timer->watcher_);
ev_tstamp after = NODE_V8_UNIXTIME(args[0]);
ev_tstamp repeat = NODE_V8_UNIXTIME(args[1]);
ev_timer_init(&timer->watcher_, Timer::OnTimeout, after, repeat);
timer->watcher_.data = timer;
ev_timer_start(EV_DEFAULT_UC_ &timer->watcher_);
timer->Ref();
if (!was_active) timer->Ref();
return Undefined();
}

1
src/node_timer.h

@ -18,6 +18,7 @@ class Timer : ObjectWrap {
Timer () : ObjectWrap () {
// dummy timeout values
ev_timer_init(&watcher_, OnTimeout, 0., 1.);
watcher_.data = this;
}
~Timer();

13
test/pummel/test-tcp-timeout.js

@ -1,21 +1,22 @@
require("../common");
tcp = require("tcp");
net = require("net");
exchanges = 0;
starttime = null;
timeouttime = null;
timeout = 1000;
var echo_server = tcp.createServer(function (socket) {
var echo_server = net.createServer(function (socket) {
socket.setTimeout(timeout);
socket.addListener("timeout", function (d) {
socket.addListener("timeout", function () {
puts("server timeout");
timeouttime = new Date;
p(timeouttime);
socket.forceClose();
});
socket.addListener("data", function (d) {
p(d);
puts(d);
socket.write(d);
});
@ -27,7 +28,7 @@ var echo_server = tcp.createServer(function (socket) {
echo_server.listen(PORT);
puts("server listening at " + PORT);
var client = tcp.createConnection(PORT);
var client = net.createConnection(PORT);
client.setEncoding("UTF8");
client.setTimeout(0); // disable the timeout for client
client.addListener("connect", function () {
@ -53,7 +54,7 @@ client.addListener("data", function (chunk) {
client.addListener("timeout", function () {
puts("client timeout - this shouldn't happen");
assert.equal(false, true);
assert.ok(false);
});
client.addListener("end", function () {

Loading…
Cancel
Save