diff options
author | Micael Karlberg <[email protected]> | 2019-05-14 18:59:56 +0200 |
---|---|---|
committer | Micael Karlberg <[email protected]> | 2019-05-29 13:47:40 +0200 |
commit | fe0bd092d56260e0a8d874076182717244834d14 (patch) | |
tree | 98bb7dee84030cd2cfe04006eea5e42125f73cc9 /erts/emulator | |
parent | 1c3d45e92e34864e6e2d8042f3a79a3513c7b240 (diff) | |
download | otp-fe0bd092d56260e0a8d874076182717244834d14.tar.gz otp-fe0bd092d56260e0a8d874076182717244834d14.tar.bz2 otp-fe0bd092d56260e0a8d874076182717244834d14.zip |
[esock|test] Preliminary Domain = local update for ttest
OTP-15822
Diffstat (limited to 'erts/emulator')
-rw-r--r-- | erts/emulator/test/socket_test_ttest_tcp_socket.erl | 59 |
1 files changed, 48 insertions, 11 deletions
diff --git a/erts/emulator/test/socket_test_ttest_tcp_socket.erl b/erts/emulator/test/socket_test_ttest_tcp_socket.erl index 0ae2412e4c..6a54d70d58 100644 --- a/erts/emulator/test/socket_test_ttest_tcp_socket.erl +++ b/erts/emulator/test/socket_test_ttest_tcp_socket.erl @@ -24,7 +24,7 @@ accept/1, accept/2, active/2, close/1, - connect/2, connect/3, + connect/1, connect/2, connect/3, controlling_process/2, listen/0, listen/1, listen/2, port/1, @@ -36,6 +36,8 @@ ]). +-define(LIB, socket_test_lib). + -define(READER_RECV_TIMEOUT, 1000). -define(DATA_MSG(Sock, Method, Data), @@ -100,30 +102,56 @@ close(#{sock := Sock, reader := Pid}) -> socket:close(Sock). %% Create a socket and connect it to a peer -connect(Addr, Port) -> - connect(Addr, Port, #{method => plain}). - -connect(Addr, Port, #{method := Method} = Opts) -> +connect(ServerPath) when is_list(ServerPath) -> + Domain = local, + ServerSA = #{family => Domain, path => ServerPath}, + Opts = #{domain => Domain, + proto => default, + method => plain}, + do_connect(ServerSA, Opts). + +connect(Addr, Port) when is_tuple(Addr) andalso is_integer(Port) -> + Domain = inet, + ServerSA = #{family => Domain, + addr => Addr, + port => Port}, + Opts = #{domain => Domain, + proto => tcp, + method => plain}, + do_connect(ServerSA, Opts); +connect(ServerPath, + #{domain := local = Domain, proto := default} = Opts) + when is_list(ServerPath) -> + ServerSA = #{family => Domain, path => ServerPath}, + do_connect(ServerSA, Opts). + +connect(Addr, Port, #{domain := Domain, proto := tcp} = Opts) -> + ServerSA = #{family => Domain, + addr => Addr, + port => Port}, + do_connect(ServerSA, Opts). + +do_connect(ServerSA, #{domain := Domain, + proto := Proto, + method := Method} = Opts) -> try begin Sock = - case socket:open(inet, stream, tcp) of + case socket:open(Domain, stream, Proto) of {ok, S} -> S; {error, OReason} -> throw({error, {open, OReason}}) end, - case socket:bind(Sock, any) of + LocalSA = which_sa(Domain), + case socket:bind(Sock, LocalSA) of {ok, _} -> ok; {error, BReason} -> (catch socket:close(Sock)), throw({error, {bind, BReason}}) end, - SA = #{family => inet, - addr => Addr, - port => Port}, - case socket:connect(Sock, SA) of + case socket:connect(Sock, ServerSA) of ok -> ok; {error, CReason} -> @@ -140,6 +168,15 @@ connect(Addr, Port, #{method := Method} = Opts) -> ERROR end. +which_sa(local = Domain) -> + #{family => Domain, + path => mk_unique_path()}; +which_sa(_) -> + any. + +mk_unique_path() -> + [NodeName | _] = string:tokens(atom_to_list(node()), [$@]), + ?LIB:f("/tmp/esock_~s_~w", [NodeName, erlang:system_time(nanosecond)]). maybe_start_stats_timer(#{stats_to := Pid, stats_interval := T}, |