*** empty log message ***
authorMatthew Mondor <mmondor@pulsar-zone.net>
Sun, 7 Jan 2007 11:27:54 +0000 (11:27 +0000)
committerMatthew Mondor <mmondor@pulsar-zone.net>
Sun, 7 Jan 2007 11:27:54 +0000 (11:27 +0000)
mmsoftware/js/js-sh/app/httpd/httpd.js

index 73d1459..a294543 100644 (file)
@@ -1,4 +1,4 @@
-/* $Id: httpd.js,v 1.48 2007/01/07 11:01:59 mmondor Exp $ */
+/* $Id: httpd.js,v 1.49 2007/01/07 11:27:54 mmondor Exp $ */
 
 /*
  * Copyright (c) 2005-2006, Matthew Mondor
@@ -36,6 +36,7 @@
  *   eventually appears to be garbage collected!  Actually, even if a single
  *   one, it eventually gets closed!  Maybe a bug in FD where it doesn't
  *   properly root its objects in a GC-friendly way?
+ *   Another possibility would be a bug in PollSet (i.e. int overflow?)
  * - XXX Fix n/a bug in Location: when no Host: is provided for HTTP 1.0/1.1
  *
  * Transfer states
@@ -81,7 +82,7 @@
  * Server identification
  */
 const SERVER_VERSION = 'mmondor_js_httpd/0.2.1 (NetBSD)';
-const SERVER_CVSID = '$Id: httpd.js,v 1.48 2007/01/07 11:01:59 mmondor Exp $';
+const SERVER_CVSID = '$Id: httpd.js,v 1.49 2007/01/07 11:27:54 mmondor Exp $';
 
 
 
@@ -1719,22 +1720,33 @@ function PollSet()
        this.count = 0;
        this.min = 0;
        this.set = {};
+       this.locked = false;
 }
 
 PollSet.prototype = {
        add: function(fd)
        {
 
-               if (this.count > 9999999)
+               if (this.count > 999999)
                        this.count = this.min + 1;
-               fd.fdidx = this.count++;
-               this.set[fd.fdidx] = fd;
+               fd.fdidx = this.count;
+               this.set[this.count++] = fd;
        },
 
        remove: function(fd)
        {
 
-               delete this.set[fd.fdidx];
+               if (fd.fdidx > this.min)
+                       delete this.set[fd.fdidx];
+       },
+
+       staticlock: function()
+       {
+
+               if (this.locked)
+                       throw ('PollSet already staticlock()ed');
+               this.min = ++this.count;
+               this.locked = true;
        }
 };
 
@@ -1851,9 +1863,10 @@ function main() {
                exit();
 
        /*
-        * Reset pollset.min to avoid overwriting static descriptors
+        * Protect all currently added descriptors to the set from removal
+        * or from being overridden, makig them static.
         */
-       pollset.min = pollset.count;
+       pollset.staticlock();
 
        /*
         * Main loop
@@ -1984,11 +1997,12 @@ function main() {
 
                        /*
                         * If descriptor is a bound one, attempt to accept
-                        * the new client connection
+                        * the new client connection.  Continue anyway on other
+                        * types of events for the listening descriptor.
                         */
-                       if (efd.type == STYPE_LISTEN &&
-                           (efd.revents & FD.POLLIN) != 0) {
-                               try {
+                       if (efd.type == STYPE_LISTEN) {
+                               if ((efd.revents & FD.POLLIN) != 0) {
+                                       try {
                                        fd = efd.accept();
                                        if (!climits.add(fd)) {
                                                http_error(fd, 403.9,
@@ -2005,9 +2019,11 @@ function main() {
                                         */
                                        fd.state_http_init(cur);
                                        pollset.add(fd);
-                               } catch (x) {
-                                       stderr.write(x + " at accept(2)\n");
-                                       fd.close();
+                                       } catch (x) {
+                                               stderr.write(x +
+                                                   " at accept(2)\n");
+                                               fd.close();
+                                       }
                                }
                                continue;
                        }