diff options
author | Micael Karlberg <[email protected]> | 2011-04-12 18:12:27 +0200 |
---|---|---|
committer | Micael Karlberg <[email protected]> | 2011-04-12 18:12:27 +0200 |
commit | f9346bbd247b8fcef5e4f68e94b429cb39f9d4ac (patch) | |
tree | 08a69b3f5050ab97e1571b99bff1a494780bccd2 /lib/inets/src | |
parent | a0c01db642374fb9fbbbb47263929f1e442e20d7 (diff) | |
parent | d0f399b4b08b5cd9fb54bec5d71c82b560199c86 (diff) | |
download | otp-f9346bbd247b8fcef5e4f68e94b429cb39f9d4ac.tar.gz otp-f9346bbd247b8fcef5e4f68e94b429cb39f9d4ac.tar.bz2 otp-f9346bbd247b8fcef5e4f68e94b429cb39f9d4ac.zip |
Merge branch 'bmk/inets/httpd/extended_fd/OTP-9202' into bmk/inets/inet56_integration
OTP-9202
Diffstat (limited to 'lib/inets/src')
-rw-r--r-- | lib/inets/src/http_lib/http_transport.erl | 69 | ||||
-rw-r--r-- | lib/inets/src/http_server/httpd_sup.erl | 45 | ||||
-rw-r--r-- | lib/inets/src/inets_app/inets.appup.src | 8 |
3 files changed, 75 insertions, 47 deletions
diff --git a/lib/inets/src/http_lib/http_transport.erl b/lib/inets/src/http_lib/http_transport.erl index 0024d19fc1..173911b868 100644 --- a/lib/inets/src/http_lib/http_transport.erl +++ b/lib/inets/src/http_lib/http_transport.erl @@ -23,7 +23,7 @@ -export([ start/1, connect/3, connect/4, - listen/2, listen/3, + listen/2, listen/3, listen/4, accept/2, accept/3, close/2, send/3, @@ -136,10 +136,11 @@ connect({essl, SslConfig}, {Host, Port}, _, Timeout) -> %%------------------------------------------------------------------------- -%% listen(SocketType, Port) -> {ok, Socket} | {error, Reason} +%% listen(SocketType, Addr, Port, Fd) -> {ok, Socket} | {error, Reason} %% SocketType = ip_comm | {ssl, SSLConfig} %% Port = integer() -%% Socket = socket() +%% Socket = socket() +%% Fd = undefined | fd() %% %% Description: Sets up socket to listen on the port Port on the local %% host using either gen_tcp or ssl. In the gen_tcp case the port @@ -151,13 +152,8 @@ connect({essl, SslConfig}, {Host, Port}, _, Timeout) -> listen(SocketType, Port) -> listen(SocketType, undefined, Port). -listen(ip_comm, Addr, Port) -> - case (catch listen_ip_comm(Addr, Port)) of - {'EXIT', Reason} -> - {error, {exit, Reason}}; - Else -> - Else - end; +listen(ip_comm = SocketType, Addr, Port) -> + listen(SocketType, Addr, Port, undefined); %% Wrapper for backaward compatibillity listen({ssl, SSLConfig}, Addr, Port) -> @@ -186,9 +182,17 @@ listen({essl, SSLConfig} = Ssl, Addr, Port) -> Opt2 = [{ssl_imp, new}, {reuseaddr, true} | Opt], ssl:listen(Port, Opt2). +listen(ip_comm, Addr, Port, Fd) -> + case (catch listen_ip_comm(Addr, Port, Fd)) of + {'EXIT', Reason} -> + {error, {exit, Reason}}; + Else -> + Else + end. + -listen_ip_comm(Addr, Port) -> - {NewPort, Opts, IpFamily} = get_socket_info(Addr, Port), +listen_ip_comm(Addr, Port, Fd) -> + {NewPort, Opts, IpFamily} = get_socket_info(Addr, Port, Fd), case IpFamily of inet6fb4 -> Opts2 = [inet6 | Opts], @@ -223,29 +227,36 @@ listen_ip_comm(Addr, Port) -> ipfamily_default(Addr, Port) -> httpd_conf:lookup(Addr, Port, ipfamily, inet6fb4). -get_socket_info(Addr, Port) -> - Key = list_to_atom("httpd_" ++ integer_to_list(Port)), - BaseOpts = [{backlog, 128}, {reuseaddr, true}], +get_socket_info(Addr, Port, Fd0) -> + BaseOpts = [{backlog, 128}, {reuseaddr, true}], IpFamilyDefault = ipfamily_default(Addr, Port), - case init:get_argument(Key) of - {ok, [[Value]]} -> - {Fd, IpFamily} = - case string:tokens(Value, [$|]) of - [FdStr, IpFamilyStr] -> - Fd0 = fd_of(FdStr), - IpFamily0 = ip_family_of(IpFamilyStr), - {Fd0, IpFamily0}; - [FdStr] -> - {fd_of(FdStr), IpFamilyDefault}; - _ -> - throw({error, {bad_descriptor, Value}}) - end, + %% The presence of a file descriptor takes precedence + case get_fd(Port, Fd0, IpFamilyDefault) of + {Fd, IpFamily} -> {0, sock_opt(ip_comm, Addr, [{fd, Fd} | BaseOpts]), IpFamily}; - error -> + undefined -> {Port, sock_opt(ip_comm, Addr, BaseOpts), IpFamilyDefault} end. +get_fd(Port, undefined = _Fd, IpFamilyDefault) -> + FdKey = list_to_atom("httpd_" ++ integer_to_list(Port)), + case init:get_argument(FdKey) of + {ok, [[Value]]} -> + case string:tokens(Value, [$|]) of + [FdStr, IpFamilyStr] -> + {fd_of(FdStr), ip_family_of(IpFamilyStr)}; + [FdStr] -> + {fd_of(FdStr), IpFamilyDefault}; + _ -> + throw({error, {bad_descriptor, Value}}) + end; + error -> + undefined + end; +get_fd(_Port, Fd, IpFamilyDefault) -> + {Fd, IpFamilyDefault}. + fd_of(FdStr) -> case (catch list_to_integer(FdStr)) of Fd when is_integer(Fd) -> diff --git a/lib/inets/src/http_server/httpd_sup.erl b/lib/inets/src/http_server/httpd_sup.erl index b248c9bcf0..d028a19bf0 100644 --- a/lib/inets/src/http_server/httpd_sup.erl +++ b/lib/inets/src/http_server/httpd_sup.erl @@ -182,24 +182,32 @@ httpd_child_spec(ConfigFile, AcceptTimeout, Debug) -> Error end. -httpd_child_spec(Config, AcceptTimeout, Debug, Addr, 0) -> - case start_listen(Addr, 0, Config) of - {Pid, {NewPort, NewConfig, ListenSocket}} -> - Name = {httpd_instance_sup, Addr, NewPort}, - StartFunc = {httpd_instance_sup, start_link, - [NewConfig, AcceptTimeout, - {Pid, ListenSocket}, Debug]}, - Restart = permanent, - Shutdown = infinity, - Modules = [httpd_instance_sup], - Type = supervisor, - {Name, StartFunc, Restart, Shutdown, Type, Modules}; - {Pid, {error, Reason}} -> - exit(Pid, normal), - {error, Reason} - end; - httpd_child_spec(Config, AcceptTimeout, Debug, Addr, Port) -> + case Port == 0 orelse proplists:is_defined(fd, Config) of + true -> + httpd_child_spec_listen(Config, AcceptTimeout, Debug, Addr, Port); + false -> + httpd_child_spec_nolisten(Config, AcceptTimeout, Debug, Addr, Port) + end. + +httpd_child_spec_listen(Config, AcceptTimeout, Debug, Addr, Port) -> + case start_listen(Addr, Port, Config) of + {Pid, {NewPort, NewConfig, ListenSocket}} -> + Name = {httpd_instance_sup, Addr, NewPort}, + StartFunc = {httpd_instance_sup, start_link, + [NewConfig, AcceptTimeout, + {Pid, ListenSocket}, Debug]}, + Restart = permanent, + Shutdown = infinity, + Modules = [httpd_instance_sup], + Type = supervisor, + {Name, StartFunc, Restart, Shutdown, Type, Modules}; + {Pid, {error, Reason}} -> + exit(Pid, normal), + {error, Reason} + end. + +httpd_child_spec_nolisten(Config, AcceptTimeout, Debug, Addr, Port) -> Name = {httpd_instance_sup, Addr, Port}, StartFunc = {httpd_instance_sup, start_link, [Config, AcceptTimeout, Debug]}, @@ -224,7 +232,8 @@ listen(Address, Port, Config) -> SocketType = proplists:get_value(socket_type, Config, ip_comm), case http_transport:start(SocketType) of ok -> - case http_transport:listen(SocketType, Address, Port) of + Fd = proplists:get_value(fd, Config), + case http_transport:listen(SocketType, Address, Port, Fd) of {ok, ListenSocket} -> NewConfig = proplists:delete(port, Config), {ok, NewPort} = inet:port(ListenSocket), diff --git a/lib/inets/src/inets_app/inets.appup.src b/lib/inets/src/inets_app/inets.appup.src index df18ffa9e8..c14f8d51f6 100644 --- a/lib/inets/src/inets_app/inets.appup.src +++ b/lib/inets/src/inets_app/inets.appup.src @@ -22,12 +22,14 @@ [ {load_module, ftp, soft_purge, soft_purge, []}, {load_module, http_util, soft_purge, soft_purge, []}, + {load_module, http_transport, soft_purge, soft_purge, []}, {load_module, httpd_util, soft_purge, soft_purge, [http_util]}, {load_module, httpd_file, soft_purge, soft_purge, []}, {load_module, httpd_log, soft_purge, soft_purge, []}, {load_module, mod_esi, soft_purge, soft_purge, []}, {load_module, httpc, soft_purge, soft_purge, [httpc_handler]}, {load_module, httpc_request, soft_purge, soft_purge, []}, + {update, httpd_sup, soft, soft_purge, soft_purge, [http_transport]}, {update, httpd_request_handler, soft, soft_purge, soft_purge, []}, {update, httpc_handler, soft, soft_purge, soft_purge, [httpc_request]} ] @@ -37,12 +39,14 @@ {load_module, ftp, soft_purge, soft_purge, []}, {load_module, http_chunk, soft_purge, soft_purge, []}, {load_module, http_util, soft_purge, soft_purge, []}, + {load_module, http_transport, soft_purge, soft_purge, []}, {load_module, httpd_util, soft_purge, soft_purge, [http_util]}, {load_module, httpd_file, soft_purge, soft_purge, []}, {load_module, httpd_log, soft_purge, soft_purge, []}, {load_module, mod_esi, soft_purge, soft_purge, []}, {load_module, httpc, soft_purge, soft_purge, [httpc_handler]}, {load_module, httpc_request, soft_purge, soft_purge, []}, + {update, httpd_sup, soft, soft_purge, soft_purge, [http_transport]}, {update, httpd_request_handler, soft, soft_purge, soft_purge, []}, {update, httpc_handler, soft, soft_purge, soft_purge, [httpc_request, http_chunk]} @@ -64,12 +68,14 @@ [ {load_module, ftp, soft_purge, soft_purge, []}, {load_module, http_util, soft_purge, soft_purge, []}, + {load_module, http_transport, soft_purge, soft_purge, []}, {load_module, httpd_util, soft_purge, soft_purge, [http_util]}, {load_module, httpd_file, soft_purge, soft_purge, []}, {load_module, httpd_log, soft_purge, soft_purge, []}, {load_module, mod_esi, soft_purge, soft_purge, []}, {load_module, httpc, soft_purge, soft_purge, [httpc_handler]}, {load_module, httpc_request, soft_purge, soft_purge, []}, + {update, httpd_sup, soft, soft_purge, soft_purge, [http_transport]}, {update, httpd_request_handler, soft, soft_purge, soft_purge, []}, {update, httpc_handler, soft, soft_purge, soft_purge, [httpc_request]} ] @@ -79,12 +85,14 @@ {load_module, ftp, soft_purge, soft_purge, []}, {load_module, http_chunk, soft_purge, soft_purge, []}, {load_module, http_util, soft_purge, soft_purge, []}, + {load_module, http_transport, soft_purge, soft_purge, []}, {load_module, httpd_util, soft_purge, soft_purge, [http_util]}, {load_module, httpd_file, soft_purge, soft_purge, []}, {load_module, httpd_log, soft_purge, soft_purge, []}, {load_module, mod_esi, soft_purge, soft_purge, []}, {load_module, httpc, soft_purge, soft_purge, [httpc_handler]}, {load_module, httpc_request, soft_purge, soft_purge, []}, + {update, httpd_sup, soft, soft_purge, soft_purge, [http_transport]}, {update, httpd_request_handler, soft, soft_purge, soft_purge, []}, {update, httpc_handler, soft, soft_purge, soft_purge, [httpc_request, http_chunk]} |