Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Timer clean ups

Also bugfix getting pointer to C++ class in watcher
  • Loading branch information...
commit a01d8a0d68511b14b3348143bce990329f14cc5d 1 parent b35d72d
@ry ry authored
View
7 src/node_timer.cc
@@ -91,7 +91,7 @@ Timer::OnTimeout (EV_P_ ev_timer *watcher, int revents)
Timer::~Timer ()
{
- ev_timer_stop (EV_DEFAULT_UC_ &watcher_);
+ ev_timer_stop(EV_DEFAULT_UC_ &watcher_);
}
Handle<Value>
@@ -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();
}
View
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();
View
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 () {
Please sign in to comment.
Something went wrong with that request. Please try again.