-/* $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
* 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
* 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 $';
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;
}
};
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
/*
* 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,
*/
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;
}