*** empty log message ***
authorMatthew Mondor <mmondor@pulsar-zone.net>
Tue, 12 Jul 2005 12:14:08 +0000 (12:14 +0000)
committerMatthew Mondor <mmondor@pulsar-zone.net>
Tue, 12 Jul 2005 12:14:08 +0000 (12:14 +0000)
tests/js-test/js/httpd/httpd.js
tests/js-test/js/httpd/ml_clean.js
tests/js-test/js/httpd/ml_machine.js
tests/js-test/src/classes/js_fd.c

index b949954..265bd02 100644 (file)
@@ -1,4 +1,4 @@
-/* $Id: httpd.js,v 1.53 2005/07/11 01:59:21 mmondor Exp $ */
+/* $Id: httpd.js,v 1.54 2005/07/12 12:13:48 mmondor Exp $ */
 
 /*
  * Copyright (c) 2005, Matthew Mondor
  * priority at current time.
  *
  * TODO:
+ * - Support partial content to allow resuming uploads for clients
+ *   - Report error if requested offset is too high, but seek otherwise.
+ *     Do I need to report the actual file length in Content-Length, or
+ *     only the remaining?
  * - See what to do for HEAD and PUT
  * - Possibly limit rate of connections per address like I did in
  *   mmftpd/mmsmtpd/mmpop3d/mmspawnd, a requested feature of 3s4i.
@@ -46,7 +50,7 @@
  * Server identification
  */
 SERVER_VERSION                 = 'mmondor_js_httpd/0.0.1 (NetBSD)';
-SERVER_CVSID   = '$Id: httpd.js,v 1.53 2005/07/11 01:59:21 mmondor Exp $';
+SERVER_CVSID   = '$Id: httpd.js,v 1.54 2005/07/12 12:13:48 mmondor Exp $';
 
 
 
@@ -77,7 +81,7 @@ function file_read(file)
                        contents += data;
                }
        } catch (x) {
-               err.put(x + "\n");
+               err.put(x + " at file_read()\n");
        }
        fd.close();
 
@@ -101,7 +105,7 @@ function file_read2(fd)
                        contents += data;
                }
        } catch (x) {
-               err.put(x + "\n");
+               err.put(x + " at file_read2()\n");
        }
        fd.close();
 
@@ -199,7 +203,7 @@ var session_randfd = new FD();
 try {
        session_randfd.open('/dev/urandom', FD.O_RDONLY);
 } catch (x) {
-       err.put(x + "while attempting to open /dev/urandom\n");
+       err.put(x + " while attempting to open /dev/urandom\n");
        exit();
 }
 
@@ -231,7 +235,7 @@ function Session(time, exp)
        try {
                rval = session_randfd.read(options.sess_id_size);
        } catch (x) {
-               err.put(x + "while attempting to read from /dev/urandom\n");
+               err.put(x + " while attempting to read from /dev/urandom\n");
        }
        this.sessid = '';
        for (i = 0; i < options.sess_id_size; i++)
@@ -596,12 +600,12 @@ FD.prototype.init = function(time, idx)
        /* For process_request()/process_post() */
        this.bread_buffer = '';
 
-       /* Set this socket non-blocking */
-       try {
-               this.fcntl(FD.F_SETFL, FD.O_NONBLOCK);
-       } catch (x) {
-               err.put(x + "\n");
-       }
+       /*
+        * Note that fcntl(2) and setsockopt(2) flags applied to the bound
+        * descriptors are inherited to their parent sockets at accept(2).
+        * We therefore can save a few syscalls here.
+        * We are non-blocking already, for instance.
+        */
 }
 
 /*
@@ -967,7 +971,7 @@ FD.prototype.httpRespond = function(time)
                                o = new JSO(path.real, st.st_mtime,
                                    obj.script);
                        } catch (x) {
-                               err.put(x + 'evaluating script ' + path.real
+                               err.put(x + ' evaluating script ' + path.real
                                    + "\n");
                                http_error(this, 500, 'Internal Server Error',
                                    'Please try again later.');
@@ -980,7 +984,7 @@ FD.prototype.httpRespond = function(time)
                                obj.script();
                        obj.flush(this, null);
                } catch (x) {
-                       err.put(x + 'executing script ' + path.real + "\n");
+                       err.put(x + ' executing script ' + path.real + "\n");
                        http_error(this, 500, 'Internal Server Error',
                            'Please try again later.');
                }
@@ -1228,7 +1232,7 @@ function main() {
                try {
                        var v = new VHost(vhosts[i]);
                } catch (x) {
-                       err.put(x + "\n");
+                       err.put(x + " creating VHost object\n");
                }
        }
        /*
@@ -1296,6 +1300,7 @@ function main() {
                           sock.setsockopt(FD.SO_KEEPALIVE, 1);
                         */
                        fd.setsockopt(FD.TCP_NODELAY, 1);
+                       fd.fcntl(FD.F_SETFL, FD.O_NONBLOCK);
                        fd.listen(options.max_connections);
                        /*
                         * Mark socket as bound one and add it to
@@ -1305,7 +1310,7 @@ function main() {
                        fd.bound = true;
                        set.push(fd);
                } catch (x) {
-                       err.put(x + "\n");
+                       err.put(x + " preparing listening socket\n");
                }
        }
        if (set.length == 0)
@@ -1356,7 +1361,7 @@ function main() {
                try {
                        e = FD.poll(set, exp * 1000);
                } catch (x) {
-                       err.put(x + "\n");
+                       err.put(x + " for poll(2)\n");
                        continue;
                }
 
@@ -1427,7 +1432,7 @@ function main() {
                                                set[count] = fd;
                                        }
                                } catch (x) {
-                                       err.put(x + "\n");
+                                       err.put(x + " at accept(2)\n");
                                }
                                continue;
                        }
index 96f73a9..14de995 100644 (file)
@@ -1,4 +1,4 @@
-/* $Id: ml_clean.js,v 1.2 2005/07/10 18:18:27 mmondor Exp $ */
+/* $Id: ml_clean.js,v 1.3 2005/07/12 12:13:48 mmondor Exp $ */
 
 /*
  * Copyright (c) 2004-2005, Matthew Mondor
@@ -86,38 +86,51 @@ MLTag.prototype = {
         */
        toStr: function(level)
        {
+               var str = '';
+
+               /* Null tags may exist as containers */
+               if (this.tag != null) {
+
+                       /* Open opening tag */
+                       str += this.indent_str.substr(0, level) + '<' +
+                           this.tag;
+
+                       /*
+                        * Store these immediately for performance since we
+                        * use those values several times later on, also
+                        * saves typing
+                        */
+                       var taglen = this.tag.length;
+                       var len = level + taglen + 1;
+                       var attributes = this.attributes;
+
+                       /*
+                        * Add each of our attributes with their optional
+                        * values
+                        */
+                       for (var attr in attributes) {
+                               var value;
+
+                               if (len > 70) {
+                                       len = level + taglen + 1;
+                                       str += "\n" +
+                                           this.indent_str.substr(0, len);
+                               }
+                               str += ' ' + attr;
+                               len += taglen + 1;
+                               if ((value = attributes[attr]) != null) {
+                                       str += '="' + value + '"';
+                                       len += value.length + 3;
+                               }
+                       }
 
-               /* Open opening tag */
-               var str = this.indent_str.substr(0, level) + '<' + this.tag;
-
-               /*
-                * Store these immediately for performance since we use those
-                * values several times later on, also saves typing
-                */
-               var taglen = this.tag.length;
-               var len = level + taglen + 1;
-               var attributes = this.attributes;
+                       /* Close opening tag */
+                       str += ">\n";
 
-               /* Add each of our attributes with their optional values */
-               for (var attr in attributes) {
-                       var value;
+                       /* Increase our indent level for content */
+                       level++;
 
-                       if (len > 70) {
-                               len = level + taglen + 1;
-                               str += "\n" + this.indent_str.substr(0, len);
-                       }
-                       str += ' ' + attr;
-                       len += taglen + 1;
-                       if ((value = attributes[attr]) != null) {
-                               str += '="' + value + '"';
-                               len += value.length + 3;
-                       }
                }
-               /* Close opening tag */
-               str += ">\n";
-
-               /* Increase our indent level for content */
-               level++;
 
                /*
                 * Now add all our contents, if any, which may consist of
@@ -135,13 +148,14 @@ MLTag.prototype = {
                }
 
                /*
-                * This tag required closing, so add corresponding closing tag
-                * and decrease indent level.
+                * If this tag required closing, do so
                 */
-               level--;
-               if (this.close)
-                       str += this.indent_str.substr(0, level) + '</' +
-                           this.tag + ">\n";
+               if (this.tag != null) {
+                       level--;
+                       if (this.close)
+                               str += this.indent_str.substr(0, level) +
+                                   '</' + this.tag + ">\n";
+               }
 
                return str;
        }
index d6b6c01..c0ead8b 100644 (file)
@@ -1,4 +1,4 @@
-/* $Id: ml_machine.js,v 1.2 2005/07/10 18:18:27 mmondor Exp $ */
+/* $Id: ml_machine.js,v 1.3 2005/07/12 12:13:48 mmondor Exp $ */
 
 /*
  * Copyright (c) 2004-2005, Matthew Mondor
@@ -52,31 +52,42 @@ MLTag.prototype = {
         */
        toStr: function(level)
        {
+               var str = '';
+
+               /* Null tags may exist as containers */
+               if (this.tag != null) {
+
+                       /* Open opening tag */
+                       str += '<' + this.tag;
+
+                       /*
+                        * Store these immediately for performance since we
+                        * use those values several times later on, also
+                        * saves typing
+                        */
+                       var taglen = this.tag.length;
+                       var len = taglen + 1;
+                       var attributes = this.attributes;
+
+                       /*
+                        * Add each of our attributes with their optional
+                        * values
+                        */
+                       for (var attr in attributes) {
+                               var value;
+
+                               str += ' ' + attr;
+                               len += taglen + 1;
+                               if ((value = attributes[attr]) != null) {
+                                       str += '="' + value + '"';
+                                       len += value.length + 3;
+                               }
+                       }
 
-               /* Open opening tag */
-               var str = '<' + this.tag;
+                       /* Close opening tag */
+                       str += ">";
 
-               /*
-                * Store these immediately for performance since we use those
-                * values several times later on, also saves typing
-                */
-               var taglen = this.tag.length;
-               var len = taglen + 1;
-               var attributes = this.attributes;
-
-               /* Add each of our attributes with their optional values */
-               for (var attr in attributes) {
-                       var value;
-
-                       str += ' ' + attr;
-                       len += taglen + 1;
-                       if ((value = attributes[attr]) != null) {
-                               str += '="' + value + '"';
-                               len += value.length + 3;
-                       }
                }
-               /* Close opening tag */
-               str += ">";
 
                /*
                 * Now add all our contents, if any, which may consist of
@@ -94,9 +105,9 @@ MLTag.prototype = {
                }
 
                /*
-                * This tag required closing, so add corresponding closing tag
+                * If this tag required closing, do so
                 */
-               if (this.close)
+               if (this.tag != null && this.close)
                        str += '</' + this.tag + ">";
 
                return str;
index e04bb95..73502f1 100644 (file)
@@ -1,4 +1,4 @@
-/* $Id: js_fd.c,v 1.33 2005/07/07 05:12:51 mmondor Exp $ */
+/* $Id: js_fd.c,v 1.34 2005/07/12 12:14:08 mmondor Exp $ */
 
 /*
  * Copyright (c) 2005, Matthew Mondor
@@ -1709,7 +1709,7 @@ fd_m_fcntl(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval)
                return JS_FALSE;
        }
        flags &= (O_NONBLOCK | O_APPEND);
-       if (!(flags & O_NONBLOCK) && !(flags & O_APPEND)) {
+       if ((flags & O_NONBLOCK) == 0 && (flags & O_APPEND) == 0) {
                QUEUE_EXCEPTION("Unimplemented fcntl() flag");
                return JS_FALSE;
        }