aboutsummaryrefslogtreecommitdiffstats
path: root/lib/inets
diff options
context:
space:
mode:
Diffstat (limited to 'lib/inets')
-rw-r--r--lib/inets/doc/src/inets.xml54
-rw-r--r--lib/inets/doc/src/notes.xml17
-rw-r--r--lib/inets/src/http_lib/http_transport.erl69
-rw-r--r--lib/inets/src/http_server/httpd_sup.erl45
-rw-r--r--lib/inets/src/inets_app/inets.appup.src8
5 files changed, 129 insertions, 64 deletions
diff --git a/lib/inets/doc/src/inets.xml b/lib/inets/doc/src/inets.xml
index c367d7fa77..a2bf42320f 100644
--- a/lib/inets/doc/src/inets.xml
+++ b/lib/inets/doc/src/inets.xml
@@ -1,4 +1,4 @@
-<?xml version="1.0" encoding="latin1" ?>
+<?xml version="1.0" encoding="iso-8859-1" ?>
<!DOCTYPE erlref SYSTEM "erlref.dtd">
<erlref>
@@ -32,8 +32,10 @@
<modulesummary>The inets services API</modulesummary>
<description>
<p>This module provides the most basic API to the
- clients and servers, that are part of the Inets application,
- such as start and stop. </p>
+ clients and servers, that are part of the Inets application,
+ such as start and stop. </p>
+
+ <marker id="common_data_types"></marker>
</description>
<section>
@@ -42,7 +44,10 @@
this module: </p>
<p><c> service() = ftpc | tftp | httpc | httpd</c></p>
<p><c> property() = atom() </c></p>
+ <marker id="functions"></marker>
+ <marker id="services"></marker>
</section>
+
<funcs>
<func>
<name>services() -> [{Service, Pid}]</name>
@@ -54,11 +59,13 @@
<desc>
<p>Returns a list of currently running services.</p>
<note>
- <p>Services started as <c>stand_alone</c> will not
- be listed.</p>
+ <p>Services started as <c>stand_alone</c> will not be listed.</p>
</note>
+
+ <marker id="services_info"></marker>
</desc>
</func>
+
<func>
<name>services_info() -> [{Service, Pid, Info}]</name>
<fsummary>Returns a list of currently running services where
@@ -73,11 +80,13 @@
</type>
<desc>
<p>Returns a list of currently running services where each
- service is described by a [{Option, Value}] list. The
- information given in the list is specific for each service
- and it is probable that each service will have its own info
- function that gives you even more details about the
- service.</p>
+ service is described by a [{Option, Value}] list. The
+ information given in the list is specific for each service
+ and it is probable that each service will have its own info
+ function that gives you even more details about the
+ service.</p>
+
+ <marker id="service_names"></marker>
</desc>
</func>
@@ -89,6 +98,8 @@
</type>
<desc>
<p>Returns a list of available service names.</p>
+
+ <marker id="start"></marker>
</desc>
</func>
@@ -101,18 +112,24 @@
</type>
<desc>
<p>Starts the Inets application. Default type
- is temporary. See also
- <seealso marker="kernel:application">application(3)</seealso></p>
+ is temporary. See also
+ <seealso marker="kernel:application">application(3)</seealso>. </p>
+
+ <marker id="stop"></marker>
</desc>
</func>
+
<func>
<name>stop() -> ok </name>
<fsummary>Stops the inets application.</fsummary>
<desc>
<p>Stops the inets application. See also
- <seealso marker="kernel:application">application(3)</seealso></p>
+ <seealso marker="kernel:application">application(3)</seealso>. </p>
+
+ <marker id="start2"></marker>
</desc>
</func>
+
<func>
<name>start(Service, ServiceConfig) -> {ok, Pid} | {error, Reason}</name>
<name>start(Service, ServiceConfig, How) -> {ok, Pid} | {error, Reason}</name>
@@ -144,8 +161,11 @@
some sense the calling process has now become the top
supervisor.</p>
</note>
+
+ <marker id="stop2"></marker>
</desc>
</func>
+
<func>
<name>stop(Service, Reference) -> ok | {error, Reason} </name>
<fsummary>Stops a started service of the inets application or takes
@@ -157,9 +177,11 @@
</type>
<desc>
<p>Stops a started service of the inets application or takes
- down a "stand_alone-service" gracefully. When the
- <c>stand_alone</c> option is used in start,
- only the pid is a valid argument to stop.</p>
+ down a "stand_alone-service" gracefully. When the
+ <c>stand_alone</c> option is used in start,
+ only the pid is a valid argument to stop.</p>
+
+ <marker id="see_also"></marker>
</desc>
</func>
</funcs>
diff --git a/lib/inets/doc/src/notes.xml b/lib/inets/doc/src/notes.xml
index f9411fed2a..df3bf19066 100644
--- a/lib/inets/doc/src/notes.xml
+++ b/lib/inets/doc/src/notes.xml
@@ -77,6 +77,20 @@
<p>Own Id: OTP-9157</p>
</item>
+ <item>
+ <p>[httpd] Extended support for file descriptors.
+ In order to be able to bind to a privileged port
+ without running the erlang VM as root, the support
+ for using file descriptors has been improved.
+ It is now possible to add the file descriptor to the config
+ (option fd) when calling the
+ <seealso marker="inets#start2">inets:start(httpd, ...)</seealso>
+ function. </p>
+ <p>Attila Rajmund Nohl</p>
+ <p>Own Id: OTP-9202</p>
+ <p>Aux Id: seq11819</p>
+ </item>
+
</list>
</section>
@@ -162,7 +176,8 @@
are URL-encoded. Added support in http-client to use
URL-encoding. Also added the missing include directory
for the inets application.</p>
- <p>Own Id: OTP-8940 Aux Id: seq11735 </p>
+ <p>Own Id: OTP-8940</p>
+ <p>Aux Id: seq11735</p>
</item>
</list>
</section>
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]}