*** empty log message ***
authorMatthew Mondor <mmondor@pulsar-zone.net>
Tue, 12 Jul 2005 13:00:14 +0000 (13:00 +0000)
committerMatthew Mondor <mmondor@pulsar-zone.net>
Tue, 12 Jul 2005 13:00:14 +0000 (13:00 +0000)
tests/js-test/js/httpd/httpd.js

index 265bd02..08407bb 100644 (file)
@@ -1,4 +1,4 @@
-/* $Id: httpd.js,v 1.54 2005/07/12 12:13:48 mmondor Exp $ */
+/* $Id: httpd.js,v 1.55 2005/07/12 13:00:14 mmondor Exp $ */
 
 /*
  * Copyright (c) 2005, Matthew Mondor
@@ -50,7 +50,7 @@
  * Server identification
  */
 SERVER_VERSION                 = 'mmondor_js_httpd/0.0.1 (NetBSD)';
-SERVER_CVSID   = '$Id: httpd.js,v 1.54 2005/07/12 12:13:48 mmondor Exp $';
+SERVER_CVSID   = '$Id: httpd.js,v 1.55 2005/07/12 13:00:14 mmondor Exp $';
 
 
 
@@ -70,10 +70,19 @@ function file_read(file)
 {
        var contents = '';
        var data;
+       var fd;
 
-       var fd = new FD();
        try {
-               fd.open(file, FD.O_RDONLY);
+               /*
+                * If we were provided with a filename, rather than a
+                * filedescriptor object, open the filename.  Otherwise,
+                * read from the specified FD.
+                */
+               if (typeof file != 'object') {
+                       fd = new FD();
+                       fd.open(file, FD.O_RDONLY);
+               } else
+                       fd = file;
                for (;;) {
                        data = fd.read(8192);
                        if (data.length == 0)
@@ -83,31 +92,8 @@ function file_read(file)
        } catch (x) {
                err.put(x + " at file_read()\n");
        }
-       fd.close();
-
-       return contents;
-}
-
-/*
- * Similar to the above function, but works with an already open FD object
- * and closes it.
- */
-function file_read2(fd)
-{
-       var contents = '';
-       var data;
-
-       try {
-               for (;;) {
-                       data = fd.read(8192);
-                       if (data.length == 0)
-                               break;
-                       contents += data;
-               }
-       } catch (x) {
-               err.put(x + " at file_read2()\n");
-       }
-       fd.close();
+       if (typeof file != 'object')
+               fd.close();
 
        return contents;
 }
@@ -965,7 +951,7 @@ FD.prototype.httpRespond = function(time)
                        fd.close();
                } else {
                        try {
-                               data = file_read2(fd);
+                               data = file_read(fd);
                                s = 'obj.script = function() {' + data + '}';
                                eval(s);
                                o = new JSO(path.real, st.st_mtime,