[chatter] r11810 - trunk/libraries/network/koala/sources/koala

cgay at mccarthy.opendylan.org cgay at mccarthy.opendylan.org
Mon May 12 12:04:47 CEST 2008


Author: cgay
Date: Mon May 12 12:04:46 2008
New Revision: 11810

Modified:
   trunk/libraries/network/koala/sources/koala/config.dylan
   trunk/libraries/network/koala/sources/koala/koala-main.dylan
   trunk/libraries/network/koala/sources/koala/server.dylan
Log:
job: koala
Got rid of *abort-startup?* hack.  Signal an error instead.  Handle errors more
gracefully on the command line.
Changed version number to 0.9, the more-or-less standard "it's not to be trusted yet"
version number, right?  Anyway, no more arbitrary than 0.4.

Modified: trunk/libraries/network/koala/sources/koala/config.dylan
==============================================================================
--- trunk/libraries/network/koala/sources/koala/config.dylan	(original)
+++ trunk/libraries/network/koala/sources/koala/config.dylan	Mon May 12 12:04:46 2008
@@ -18,6 +18,16 @@
 // Holds the current vhost while config elements are being processed.
 define thread variable %vhost = #f;
 
+define class <configuration-error> (<koala-api-error>)
+end;
+
+define function config-error
+    (format-string :: <string>, #rest format-args)
+  signal(make(<configuration-error>,
+              format-string: format-string,
+              format-arguments: format-args))
+end;
+
 /*
 define variable *options* = make(<table>);
 
@@ -58,14 +68,6 @@
     = as(<string>, merge-locators(as(<file-locator>, config-file | defaults),
                                   defaults));
   block (return)
-    let handler <error> = method (c :: <error>, next-handler :: <function>)
-                            if (debugging-enabled?(*server*))
-                              next-handler();  // decline to handle the error
-                            else
-                              log-error("Error loading config file: %=", c);
-                              return();
-                            end;
-                          end method;
     let text = file-contents(config-loc);
     if (text)
       log-info("Loading server configuration from %s.", config-loc);
@@ -78,12 +80,12 @@
           process-config-node(xml);
         end;
       else
-        log-error("Unable to parse config file!");
-        *abort-startup?* := #t;
+        config-error("Unable to parse config file!");
       end
-    else
-      log-error("Server configuration file (%s) not found.", config-loc);
-      *abort-startup?* := #t;
+    elseif (config-file)
+      // Only blow out if user specified a config file, not if they're taking
+      // the default config file.
+      config-error("Server configuration file (%s) not found.", config-loc);
     end if;
   end block;
 end method configure-server;
@@ -263,9 +265,8 @@
         := merge-locators(as(<directory-locator>, loc), server-root(*server*));
       log-info("Server root set to %s", loc);
     else
-      warn("Invalid <SERVER-ROOT> spec.  "
-           "The 'location' attribute must be specified.");
-      *abort-startup?* := #t;
+      config-error("Invalid <SERVER-ROOT> spec.  "
+                   "The 'location' attribute must be specified.");
     end;
   else
     warn("The <SERVER-ROOT> element is only valid at top-level "

Modified: trunk/libraries/network/koala/sources/koala/koala-main.dylan
==============================================================================
--- trunk/libraries/network/koala/sources/koala/koala-main.dylan	(original)
+++ trunk/libraries/network/koala/sources/koala/koala-main.dylan	Mon May 12 12:04:46 2008
@@ -50,16 +50,20 @@
                    usage: "koala [options]",
                    description: desc);
   else
-    let port-string = option-value-by-long-name(parser, "port") | "80";
-    let listeners = option-value-by-long-name(parser, "listen");
-    let server = make(<http-server>,
-                      listeners: iff(empty?(listeners),
-                                     #["0.0.0.0:80"],
-                                     listeners),
-                      debug: option-value-by-long-name(parser, "debug"),
-                      port: string-to-integer(port-string));
-    start-server(server,
-                 config-file: option-value-by-long-name(parser, "config"));
-  end;
+    block ()
+      let port-string = option-value-by-long-name(parser, "port") | "80";
+      let listeners = option-value-by-long-name(parser, "listen");
+      let server = make(<http-server>,
+                        listeners: iff(empty?(listeners),
+                                       #["0.0.0.0:80"],
+                                       listeners),
+                        debug: option-value-by-long-name(parser, "debug"),
+                        port: string-to-integer(port-string));
+      start-server(server,
+                   config-file: option-value-by-long-name(parser, "config"));
+    exception (ex :: <error>)
+      format(*standard-error*, "Error: %s\n", ex)
+    end;
+  end if;
 end function koala-main;
 

Modified: trunk/libraries/network/koala/sources/koala/server.dylan
==============================================================================
--- trunk/libraries/network/koala/sources/koala/server.dylan	(original)
+++ trunk/libraries/network/koala/sources/koala/server.dylan	Mon May 12 12:04:46 2008
@@ -8,13 +8,7 @@
 
 define constant $http-version = "HTTP/1.1";
 define constant $server-name = "Koala";
-define constant $server-version = "0.4";
-
-// This may be set true by config file loading code, in which case
-// start-server will be a no-op.
-// todo -- Just raise an exception instead (or at least make this a thread variable).
-define variable *abort-startup?* :: <boolean> = #f;
-
+define constant $server-version = "0.9";
 define constant $server-header-value = concatenate($server-name, "/", $server-version);
 
 // This is needed to handle sockets shutdown.
@@ -307,24 +301,19 @@
   dynamic-bind (*server* = server)
     init-server(server, config-file: config-file);
   end;
-  if (*abort-startup?*)
-    log-error("Server startup aborted due to the previous errors");
-    #f
-  else
-    for (listener in server.server-listeners)
-      start-http-listener(server, listener)
-    end;
-    if (wait)
-      wait-for-listeners-to-start(server.server-listeners);
-    end;
-    if (~background)
-      // Apparently when the main thread dies in an Open Dylan application
-      // the application exits without waiting for spawned threads to die,
-      // so join-listeners keeps the main thread alive until all listeners die.
-      join-listeners(server);
-    end;
-    #t
-  end if
+  for (listener in server.server-listeners)
+    start-http-listener(server, listener)
+  end;
+  if (wait)
+    wait-for-listeners-to-start(server.server-listeners);
+  end;
+  if (~background)
+    // Apparently when the main thread dies in an Open Dylan application
+    // the application exits without waiting for spawned threads to die,
+    // so join-listeners keeps the main thread alive until all listeners die.
+    join-listeners(server);
+  end;
+  #t
 end function start-server;
 
 define function wait-for-listeners-to-start


More information about the chatter mailing list