couchdb-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From beno...@apache.org
Subject svn commit: r1061828 - /couchdb/trunk/src/couchdb/couch_httpd.erl
Date Fri, 21 Jan 2011 14:46:15 GMT
Author: benoitc
Date: Fri Jan 21 14:46:15 2011
New Revision: 1061828

URL: http://svn.apache.org/viewvc?rev=1061828&view=rev
Log:
don't use anonymous function to handle config_changes in couch_httpd.

Modified:
    couchdb/trunk/src/couchdb/couch_httpd.erl

Modified: couchdb/trunk/src/couchdb/couch_httpd.erl
URL: http://svn.apache.org/viewvc/couchdb/trunk/src/couchdb/couch_httpd.erl?rev=1061828&r1=1061827&r2=1061828&view=diff
==============================================================================
--- couchdb/trunk/src/couchdb/couch_httpd.erl (original)
+++ couchdb/trunk/src/couchdb/couch_httpd.erl Fri Jan 21 14:46:15 2011
@@ -13,7 +13,8 @@
 -module(couch_httpd).
 -include("couch_db.hrl").
 
--export([start_link/0, start_link/1, stop/0, handle_request/5]).
+-export([start_link/0, start_link/1, stop/0, config_change/2, 
+        handle_request/5]).
 
 -export([header_value/2,header_value/3,qs_value/2,qs_value/3,qs/1,qs_json_value/3]).
 -export([path/1,absolute_uri/2,body_length/1]).
@@ -96,42 +97,45 @@ start_link(Name, Options) ->
         ])
     end,
 
-    % and off we go
-
-    {ok, Pid} = case mochiweb_http:start(Options ++ ServerOptions ++ [
-        {loop, Loop},
-        {name, Name},
-        {ip, BindAddress}
-    ]) of
-    {ok, MochiPid} -> {ok, MochiPid};
-    {error, Reason} ->
-        io:format("Failure to start Mochiweb: ~s~n",[Reason]),
-        throw({error, Reason})
-    end,
-
-    ok = couch_config:register(
-        fun("httpd", "bind_address") ->
-            ?MODULE:stop();
-        ("httpd", "port") ->
-            ?MODULE:stop();
-        ("httpd", "default_handler") ->
-            ?MODULE:stop();
-        ("httpd", "server_options") ->
-            ?MODULE:stop();
-        ("httpd", "socket_options") ->
-            ?MODULE:stop();
-        ("httpd_global_handlers", _) ->
-            ?MODULE:stop();
-        ("httpd_db_handlers", _) ->
-            ?MODULE:stop();
-        ("vhosts", _) ->
-            ?MODULE:stop();
-        ("ssl", _) ->
-            ?MODULE:stop()
-        end, Pid),
+    % set mochiweb options
+    FinalOptions = lists:append([Options, ServerOptions, [
+            {loop, Loop},
+            {name, Name},
+            {ip, BindAddress}]]),
+
+    % launch mochiweb
+    {ok, Pid} = case mochiweb_http:start(FinalOptions) of
+        {ok, MochiPid} -> 
+            {ok, MochiPid};
+        {error, Reason} ->
+            io:format("Failure to start Mochiweb: ~s~n",[Reason]),
+            throw({error, Reason})
+    end,
 
+    ok = couch_config:register(fun ?MODULE:config_change/2, Pid),
     {ok, Pid}.
 
+
+stop() ->
+    mochiweb_http:stop(?MODULE).
+
+config_change("httpd", "bind_addres") ->
+    ?MODULE:stop();
+config_change("httpd", "port") ->
+    ?MODULE:stop();
+config_change("httpd", "default_handler") ->
+    ?MODULE:stop();
+config_change("httpd", "socket_options") ->
+    ?MODULE:stop();
+config_change("httpd_global_handlers", _) ->
+    ?MODULE:stop();
+config_change("httpd_db_handlers", _) ->
+    ?MODULE:stop();
+config_change("vhosts", _) ->
+    ?MODULE:stop();
+config_change("ssl", _) ->
+    ?MODULE:stop().
+
 % SpecStr is a string like "{my_module, my_fun}"
 %  or "{my_module, my_fun, <<"my_arg">>}"
 make_arity_1_fun(SpecStr) ->
@@ -162,10 +166,6 @@ make_arity_3_fun(SpecStr) ->
 make_fun_spec_strs(SpecStr) ->
     re:split(SpecStr, "(?<=})\\s*,\\s*(?={)", [{return, list}]).
 
-stop() ->
-    mochiweb_http:stop(?MODULE).
-
-
 handle_request(MochiReq, DefaultFun, UrlHandlers, DbUrlHandlers, 
     DesignUrlHandlers) ->
 



Mime
View raw message