TCP timeout opt-in instead of opt-out
authorRyan Dahl <ry@tinyclouds.org>
Fri, 12 Mar 2010 20:38:27 +0000 (12:38 -0800)
committerRyan Dahl <ry@tinyclouds.org>
Fri, 12 Mar 2010 20:39:37 +0000 (12:39 -0800)
For speed, idle connections are super cheap.

lib/net.js

index 218d66b..36fd0cc 100644 (file)
@@ -145,15 +145,17 @@ var timeout = new (function () {
 
 
   var unenroll = this.unenroll = function (socket) {
-    socket._idleNext._idlePrev = socket._idlePrev;
-    socket._idlePrev._idleNext = socket._idleNext;
-
-    var list = lists[socket._idleTimeout];
-    // if empty then stop the watcher
-    //sys.puts('unenroll');
-    if (list && list._idlePrev == list) {
-      //sys.puts('unenroll: list empty');
-      list.stop();
+    if (socket._idleNext) {
+      socket._idleNext._idlePrev = socket._idlePrev;
+      socket._idlePrev._idleNext = socket._idleNext;
+
+      var list = lists[socket._idleTimeout];
+      // if empty then stop the watcher
+      //sys.puts('unenroll');
+      if (list && list._idlePrev == list) {
+        //sys.puts('unenroll: list empty');
+        list.stop();
+      }
     }
   };
 
@@ -256,8 +258,6 @@ function _doFlush () {
 }
 
 function initSocket (self) {
-  timeout.enroll(self, 60*1000); // default timeout, 60 seconds
-
   self._readWatcher = ioWatchers.alloc();
   self._readWatcher.callback = function () {
     // If this is the first recv (recvBuffer doesn't exist) or we've used up