aboutsummaryrefslogtreecommitdiffstats
path: root/lib/inets/src/http_server
diff options
context:
space:
mode:
authorIngela Anderton Andin <[email protected]>2013-02-20 17:18:43 +0100
committerIngela Anderton Andin <[email protected]>2013-02-20 17:18:43 +0100
commitda3797589463002f28fc42ef27872650fe1de938 (patch)
tree381d366a095356098b6487d24a8d22604de473fa /lib/inets/src/http_server
parentbaca1b6cf223b03786ea47fc101f4249bda3cb3c (diff)
downloadotp-da3797589463002f28fc42ef27872650fe1de938.tar.gz
otp-da3797589463002f28fc42ef27872650fe1de938.tar.bz2
otp-da3797589463002f28fc42ef27872650fe1de938.zip
inets httpd: Handle ipfamily option correctly when listning to port 0
Diffstat (limited to 'lib/inets/src/http_server')
-rw-r--r--lib/inets/src/http_server/httpd_acceptor.erl38
-rw-r--r--lib/inets/src/http_server/httpd_acceptor_sup.erl20
-rw-r--r--lib/inets/src/http_server/httpd_manager.erl8
-rw-r--r--lib/inets/src/http_server/httpd_sup.erl5
4 files changed, 37 insertions, 34 deletions
diff --git a/lib/inets/src/http_server/httpd_acceptor.erl b/lib/inets/src/http_server/httpd_acceptor.erl
index 08ee9ee0d0..1bffcc1f12 100644
--- a/lib/inets/src/http_server/httpd_acceptor.erl
+++ b/lib/inets/src/http_server/httpd_acceptor.erl
@@ -1,7 +1,7 @@
%%
%% %CopyrightBegin%
%%
-%% Copyright Ericsson AB 2001-2011. All Rights Reserved.
+%% Copyright Ericsson AB 2001-2013. All Rights Reserved.
%%
%% The contents of this file are subject to the Erlang Public License,
%% Version 1.1, (the "License"); you may not use this file except in
@@ -24,10 +24,10 @@
-include("inets_internal.hrl").
%% Internal application API
--export([start_link/5, start_link/6]).
+-export([start_link/6, start_link/7]).
%% Other exports (for spawn's etc.)
--export([acceptor_init/6, acceptor_init/7, acceptor_loop/5]).
+-export([acceptor_init/7, acceptor_init/8, acceptor_loop/6]).
%%
%% External API
@@ -35,27 +35,27 @@
%% start_link
-start_link(Manager, SocketType, Addr, Port, ConfigDb, AcceptTimeout) ->
+start_link(Manager, SocketType, Addr, Port, IpFamily, ConfigDb, AcceptTimeout) ->
?hdrd("start link",
[{manager, Manager},
{socket_type, SocketType},
{address, Addr},
{port, Port},
{timeout, AcceptTimeout}]),
- Args = [self(), Manager, SocketType, Addr, Port, ConfigDb, AcceptTimeout],
+ Args = [self(), Manager, SocketType, Addr, Port, IpFamily, ConfigDb, AcceptTimeout],
proc_lib:start_link(?MODULE, acceptor_init, Args).
-start_link(Manager, SocketType, ListenSocket, ConfigDb, AcceptTimeout) ->
+start_link(Manager, SocketType, ListenSocket, IpFamily, ConfigDb, AcceptTimeout) ->
?hdrd("start link",
[{manager, Manager},
{socket_type, SocketType},
{listen_socket, ListenSocket},
{timeout, AcceptTimeout}]),
- Args = [self(), Manager, SocketType, ListenSocket,
+ Args = [self(), Manager, SocketType, ListenSocket, IpFamily,
ConfigDb, AcceptTimeout],
proc_lib:start_link(?MODULE, acceptor_init, Args).
-acceptor_init(Parent, Manager, SocketType, {ListenOwner, ListenSocket},
+acceptor_init(Parent, Manager, SocketType, {ListenOwner, ListenSocket}, IpFamily,
ConfigDb, AcceptTimeout) ->
?hdrd("acceptor init",
[{parent, Parent},
@@ -66,9 +66,9 @@ acceptor_init(Parent, Manager, SocketType, {ListenOwner, ListenSocket},
{timeout, AcceptTimeout}]),
link(ListenOwner),
proc_lib:init_ack(Parent, {ok, self()}),
- acceptor_loop(Manager, SocketType, ListenSocket, ConfigDb, AcceptTimeout).
+ acceptor_loop(Manager, SocketType, ListenSocket, IpFamily, ConfigDb, AcceptTimeout).
-acceptor_init(Parent, Manager, SocketType, Addr, Port,
+acceptor_init(Parent, Manager, SocketType, Addr, Port, IpFamily,
ConfigDb, AcceptTimeout) ->
?hdrd("acceptor init",
[{parent, Parent},
@@ -77,20 +77,20 @@ acceptor_init(Parent, Manager, SocketType, Addr, Port,
{address, Addr},
{port, Port},
{timeout, AcceptTimeout}]),
- case (catch do_init(SocketType, Addr, Port)) of
+ case (catch do_init(SocketType, Addr, Port, IpFamily)) of
{ok, ListenSocket} ->
proc_lib:init_ack(Parent, {ok, self()}),
acceptor_loop(Manager, SocketType,
- ListenSocket, ConfigDb, AcceptTimeout);
+ ListenSocket, IpFamily,ConfigDb, AcceptTimeout);
Error ->
proc_lib:init_ack(Parent, Error),
error
end.
-do_init(SocketType, Addr, Port) ->
+do_init(SocketType, Addr, Port, IpFamily) ->
?hdrt("do init", []),
do_socket_start(SocketType),
- ListenSocket = do_socket_listen(SocketType, Addr, Port),
+ ListenSocket = do_socket_listen(SocketType, Addr, Port, IpFamily),
{ok, ListenSocket}.
@@ -105,9 +105,9 @@ do_socket_start(SocketType) ->
end.
-do_socket_listen(SocketType, Addr, Port) ->
+do_socket_listen(SocketType, Addr, Port, IpFamily) ->
?hdrt("do socket listen", []),
- case http_transport:listen(SocketType, Addr, Port) of
+ case http_transport:listen(SocketType, Addr, Port, IpFamily) of
{ok, ListenSocket} ->
ListenSocket;
{error, Reason} ->
@@ -121,7 +121,7 @@ do_socket_listen(SocketType, Addr, Port) ->
%% acceptor
-acceptor_loop(Manager, SocketType, ListenSocket, ConfigDb, AcceptTimeout) ->
+acceptor_loop(Manager, SocketType, ListenSocket, IpFamily, ConfigDb, AcceptTimeout) ->
?hdrd("awaiting accept",
[{manager, Manager},
{socket_type, SocketType},
@@ -133,12 +133,12 @@ acceptor_loop(Manager, SocketType, ListenSocket, ConfigDb, AcceptTimeout) ->
handle_connection(Manager, ConfigDb, AcceptTimeout,
SocketType, Socket),
?MODULE:acceptor_loop(Manager, SocketType,
- ListenSocket, ConfigDb,AcceptTimeout);
+ ListenSocket, IpFamily, ConfigDb,AcceptTimeout);
{error, Reason} ->
?hdri("accept failed", [{reason, Reason}]),
handle_error(Reason, ConfigDb),
?MODULE:acceptor_loop(Manager, SocketType, ListenSocket,
- ConfigDb, AcceptTimeout);
+ IpFamily, ConfigDb, AcceptTimeout);
{'EXIT', Reason} ->
?hdri("accept exited", [{reason, Reason}]),
ReasonString =
diff --git a/lib/inets/src/http_server/httpd_acceptor_sup.erl b/lib/inets/src/http_server/httpd_acceptor_sup.erl
index 8b1e4b6c4f..df837b5a24 100644
--- a/lib/inets/src/http_server/httpd_acceptor_sup.erl
+++ b/lib/inets/src/http_server/httpd_acceptor_sup.erl
@@ -1,7 +1,7 @@
%%
%% %CopyrightBegin%
%%
-%% Copyright Ericsson AB 2001-2009. All Rights Reserved.
+%% Copyright Ericsson AB 2001-2013. All Rights Reserved.
%%
%% The contents of this file are subject to the Erlang Public License,
%% Version 1.1, (the "License"); you may not use this file except in
@@ -27,7 +27,7 @@
-behaviour(supervisor).
%% API
--export([start_link/2, start_acceptor/5, start_acceptor/6, stop_acceptor/2]).
+-export([start_link/2, start_acceptor/6, start_acceptor/7, stop_acceptor/2]).
%% Supervisor callback
-export([init/1]).
@@ -43,11 +43,11 @@ start_link(Addr, Port) ->
%% Function: [start|stop]_acceptor/5
%% Description: Starts/stops an [auth | security] worker (child) process
%%----------------------------------------------------------------------
-start_acceptor(SocketType, Addr, Port, ConfigDb, AcceptTimeout) ->
- start_worker(httpd_acceptor, SocketType, Addr, Port,
+start_acceptor(SocketType, Addr, Port, IpFamily, ConfigDb, AcceptTimeout) ->
+ start_worker(httpd_acceptor, SocketType, Addr, Port, IpFamily,
ConfigDb, AcceptTimeout, self(), []).
-start_acceptor(SocketType, Addr, Port, ConfigDb, AcceptTimeout, ListenSocket) ->
- start_worker(httpd_acceptor, SocketType, Addr, Port,
+start_acceptor(SocketType, Addr, Port, IpFamily, ConfigDb, AcceptTimeout, ListenSocket) ->
+ start_worker(httpd_acceptor, SocketType, Addr, Port, IpFamily,
ConfigDb, AcceptTimeout, ListenSocket, self(), []).
@@ -69,18 +69,18 @@ init(_) ->
make_name(Addr,Port) ->
httpd_util:make_name("httpd_acc_sup", Addr, Port).
-start_worker(M, SocketType, Addr, Port, ConfigDB, AcceptTimeout, Manager, Modules) ->
+start_worker(M, SocketType, Addr, Port, IpFamily, ConfigDB, AcceptTimeout, Manager, Modules) ->
SupName = make_name(Addr, Port),
- Args = [Manager, SocketType, Addr, Port, ConfigDB, AcceptTimeout],
+ Args = [Manager, SocketType, Addr, Port, IpFamily, ConfigDB, AcceptTimeout],
Spec = {{M, Addr, Port},
{M, start_link, Args},
permanent, timer:seconds(1), worker, [M] ++ Modules},
supervisor:start_child(SupName, Spec).
-start_worker(M, SocketType, Addr, Port, ConfigDB, AcceptTimeout, ListenSocket,
+start_worker(M, SocketType, Addr, Port, IpFamily, ConfigDB, AcceptTimeout, ListenSocket,
Manager, Modules) ->
SupName = make_name(Addr, Port),
- Args = [Manager, SocketType, ListenSocket, ConfigDB, AcceptTimeout],
+ Args = [Manager, SocketType, ListenSocket, IpFamily, ConfigDB, AcceptTimeout],
Spec = {{M, Addr, Port},
{M, start_link, Args},
permanent, timer:seconds(1), worker, [M] ++ Modules},
diff --git a/lib/inets/src/http_server/httpd_manager.erl b/lib/inets/src/http_server/httpd_manager.erl
index b44bc77c41..672a70a394 100644
--- a/lib/inets/src/http_server/httpd_manager.erl
+++ b/lib/inets/src/http_server/httpd_manager.erl
@@ -1,7 +1,7 @@
%%
%% %CopyrightBegin%
%%
-%% Copyright Ericsson AB 2000-2010. All Rights Reserved.
+%% Copyright Ericsson AB 2000-2013. All Rights Reserved.
%%
%% The contents of this file are subject to the Erlang Public License,
%% Version 1.1, (the "License"); you may not use this file except in
@@ -264,11 +264,12 @@ init([ConfigFile, ConfigList, AcceptTimeout, Addr, Port, ListenInfo]) ->
end.
do_init(ConfigFile, ConfigList, AcceptTimeout, Addr, Port) ->
+ IpFamily = proplists:get_value(ipfamily, ConfigList, inet6fb4),
NewConfigFile = proplists:get_value(file, ConfigList, ConfigFile),
ConfigDB = do_initial_store(ConfigList),
SocketType = httpd_conf:lookup_socket_type(ConfigDB),
case httpd_acceptor_sup:start_acceptor(SocketType, Addr,
- Port, ConfigDB, AcceptTimeout) of
+ Port, IpFamily, ConfigDB, AcceptTimeout) of
{ok, _Pid} ->
Status = [{max_conn, 0},
{last_heavy_load, never},
@@ -284,11 +285,12 @@ do_init(ConfigFile, ConfigList, AcceptTimeout, Addr, Port) ->
end.
do_init(ConfigFile, ConfigList, AcceptTimeout, Addr, Port, ListenInfo) ->
+ IpFamily = proplists:get_value(ipfamily, ConfigList, inet6fb4),
NewConfigFile = proplists:get_value(file, ConfigList, ConfigFile),
ConfigDB = do_initial_store(ConfigList),
SocketType = httpd_conf:lookup_socket_type(ConfigDB),
case httpd_acceptor_sup:start_acceptor(SocketType, Addr,
- Port, ConfigDB,
+ Port, IpFamily, ConfigDB,
AcceptTimeout, ListenInfo) of
{ok, _Pid} ->
Status = [{max_conn,0}, {last_heavy_load,never},
diff --git a/lib/inets/src/http_server/httpd_sup.erl b/lib/inets/src/http_server/httpd_sup.erl
index 8ee2661b04..3b1e16cf78 100644
--- a/lib/inets/src/http_server/httpd_sup.erl
+++ b/lib/inets/src/http_server/httpd_sup.erl
@@ -247,8 +247,9 @@ listen(Address, Port, Config) ->
SocketType ->
case http_transport:start(SocketType) of
ok ->
- Fd = proplists:get_value(fd, Config),
- case http_transport:listen(SocketType, Address, Port, Fd) of
+ Fd = proplists:get_value(fd, Config),
+ IpFamily = proplists:get_value(ipfamily, Config, inet6fb4),
+ case http_transport:listen(SocketType, Address, Port, Fd, IpFamily) of
{ok, ListenSocket} ->
NewConfig = proplists:delete(port, Config),
{NewPort, _} = http_transport:sockname(SocketType, ListenSocket),