aboutsummaryrefslogtreecommitdiffstats
path: root/lib/inets/test/inets_test_lib.erl
diff options
context:
space:
mode:
authorMicael Karlberg <[email protected]>2012-02-29 15:19:54 +0100
committerMicael Karlberg <[email protected]>2012-02-29 15:19:54 +0100
commit66288284701787c7b9e1775ec9bc91732c87f51d (patch)
treefbebd93cb70018893c154a7235973a1644cff702 /lib/inets/test/inets_test_lib.erl
parentfae2034ba30fd9936960418ba36b90ca7028bb3d (diff)
downloadotp-66288284701787c7b9e1775ec9bc91732c87f51d.tar.gz
otp-66288284701787c7b9e1775ec9bc91732c87f51d.tar.bz2
otp-66288284701787c7b9e1775ec9bc91732c87f51d.zip
[inets/httpc] Make inets tests behave on all IPv6 impl
Updated according to pan/inets_ipv6_test_issues as far as possible (that branch is based on master).
Diffstat (limited to 'lib/inets/test/inets_test_lib.erl')
-rw-r--r--lib/inets/test/inets_test_lib.erl115
1 files changed, 55 insertions, 60 deletions
diff --git a/lib/inets/test/inets_test_lib.erl b/lib/inets/test/inets_test_lib.erl
index a4815becba..c94be796cd 100644
--- a/lib/inets/test/inets_test_lib.erl
+++ b/lib/inets/test/inets_test_lib.erl
@@ -494,83 +494,78 @@ connect_byte(ip_comm, Host, Port, Opts0) ->
connect(ip_comm, Host, Port, Opts).
-connect(ssl, Host, Port, Opts) ->
+%% This always falls back on IPV4, but tries IPV6 first.
+connect(Proto, Host, Port, Opts0) ->
+ Opts = Opts0 -- [inet, inet6],
+ connect(Proto, Host, Port, Opts ++ [inet6], inet6).
+
+connect(ssl, Host, Port, Opts, Type) ->
tsp("connect(ssl) -> entry with"
"~n Host: ~p"
"~n Port: ~p"
- "~n Opts: ~p", [Host, Port, Opts]),
+ "~n Opts: ~p"
+ "~n Type: ~p", [Host, Port, Opts, Type]),
ssl:start(),
%% We ignore this option for ssl...
%% ...maybe we should really treat this in the same way as ip_comm...
- case ssl:connect(Host, Port, lists:delete(inet6fb4, Opts)) of
+ case ssl:connect(Host, Port, Opts) of
{ok, Socket} ->
{ok, Socket};
+ {error, Reason} when Type =:= inet6 ->
+ tsp("connect(ssl) -> failed connecting with inet6: "
+ "~n Reason: ~p"
+ "~n trying inet", [Reason]),
+ connect(ssl, Host, Port, Opts -- [inet6], inet);
{error, Reason} ->
- {error, Reason};
+ tsp("connect(ssl) -> failed connecting: "
+ "~n Reason: ~p", [Reason]),
+ {error, Reason};
Error ->
Error
end;
-connect(ip_comm, Host, Port, Opts) ->
+connect(ip_comm, Host, Port, Opts, Type) ->
tsp("connect(ip_comm) -> entry with"
"~n Host: ~p"
"~n Port: ~p"
- "~n Opts: ~p", [Host, Port, Opts]),
+ "~n Opts: ~p"
+ "~n Type: ~p", [Host, Port, Opts, Type]),
- %% We check for precence of inet6fb4.
- %% If found, we shall try inet6 and if that does not work
- %% try inet (regardless of error reason)
- case lists:delete(inet6fb4, Opts) of
- Opts ->
- %% Nope, run as usual, where we use error reason
- %% to detect if we are on IPv6 or not...
- case gen_tcp:connect(Host,Port, Opts) of
- {ok, Socket} ->
- tsp("connect success"),
- {ok, Socket};
- {error, nxdomain} ->
- tsp("connect error nxdomain when opts: ~p", [Opts]),
- connect(ip_comm, Host, Port, lists:delete(inet6, Opts));
- {error, eafnosupport} ->
- tsp("connect error eafnosupport when opts: ~p", [Opts]),
- connect(ip_comm, Host, Port, lists:delete(inet6, Opts));
- {error, econnreset} ->
- tsp("connect error econnreset when opts: ~p", [Opts]),
- connect(ip_comm, Host, Port, lists:delete(inet6, Opts));
- {error, enetunreach} ->
- tsp("connect error eafnosupport when opts: ~p", [Opts]),
- connect(ip_comm, Host, Port, lists:delete(inet6, Opts));
- {error, {enfile,_}} ->
- tsp("connect error enfile when opts: ~p", [Opts]),
- {error, enfile};
- Error ->
- tsp("connect(ip_conn) -> Unexpected error: "
- "~n Error: ~p"
- "~nwhen"
- "~n Host: ~p"
- "~n Port: ~p"
- "~n Opts: ~p"
- "~n", [Error, Host, Port, Opts]),
- Error
- end;
+ case gen_tcp:connect(Host, Port, Opts) of
+ {ok, Socket} ->
+ tsp("connect success"),
+ {ok, Socket};
- Opts2 ->
- %% Yep, so try first with inet6 and if that fails inet
- case gen_tcp:connect(Host, Port, [inet6|Opts2]) of
- {ok, Socket} ->
- tsp("connect success"),
- {ok, Socket};
- {error, Reason_inet6} ->
- tsp("inet6 connect failed: ~p", [Reason_inet6]),
- case gen_tcp:connect(Host, Port, [inet|Opts2]) of
- {ok, Socket} ->
- tsp("connect success"),
- {ok, Socket};
- {error, Reason_inet} ->
- tsp("inet connect also failed: ~p", [Reason_inet]),
- {error, {connect_failure, [{inet6, Reason_inet6},
- {inet, Reason_inet}]}}
- end
- end
+ {error, nxdomain} when Type =:= inet6 ->
+ tsp("connect error nxdomain when"
+ "~n Opts: ~p", [Opts]),
+ connect(ip_comm, Host, Port, Opts -- [inet6], inet);
+ {error, eafnosupport} when Type =:= inet6 ->
+ tsp("connect error eafnosupport when"
+ "~n Opts: ~p", [Opts]),
+ connect(ip_comm, Host, Port, Opts -- [inet6], inet);
+ {error, econnreset} when Type =:= inet6 ->
+ tsp("connect error econnreset when"
+ "~n Opts: ~p", [Opts]),
+ connect(ip_comm, Host, Port, Opts -- [inet6], inet);
+ {error, enetunreach} when Type =:= inet6 ->
+ tsp("connect error eafnosupport when"
+ "~n Opts: ~p", [Opts]),
+ connect(ip_comm, Host, Port, Opts -- [inet6], inet);
+ {error, econnrefused} when Type =:= inet6 ->
+ tsp("connect error econnrefused when"
+ "~n Opts: ~p", [Opts]),
+ connect(ip_comm, Host, Port, Opts -- [inet6], inet);
+
+ Error ->
+ tsp("connect(ip_conn) -> Fatal connect error: "
+ "~n Error: ~p"
+ "~nwhen"
+ "~n Host: ~p"
+ "~n Port: ~p"
+ "~n Opts: ~p"
+ "~n Type: ~p"
+ "~n", [Error, Host, Port, Opts, Type]),
+ Error
end.