diff options
author | Micael Karlberg <[email protected]> | 2019-04-16 12:27:51 +0200 |
---|---|---|
committer | Micael Karlberg <[email protected]> | 2019-05-29 14:21:13 +0200 |
commit | e95430644d7f9144a632b89370222c3b7119dc33 (patch) | |
tree | d7191fe8dc20927ff4c22acf24a797d5536a996f /erts/emulator/test | |
parent | 2934b6538a86d71c6a185ec5bc6fa23e1b7b9b5a (diff) | |
download | otp-e95430644d7f9144a632b89370222c3b7119dc33.tar.gz otp-e95430644d7f9144a632b89370222c3b7119dc33.tar.bz2 otp-e95430644d7f9144a632b89370222c3b7119dc33.zip |
[socket] Add nowait test case (sendmsg and recvmsg tcp4)
Added test case api_a_sendmsg_and_recvmsg_tcp4.
Diffstat (limited to 'erts/emulator/test')
-rw-r--r-- | erts/emulator/test/socket_SUITE.erl | 48 |
1 files changed, 43 insertions, 5 deletions
diff --git a/erts/emulator/test/socket_SUITE.erl b/erts/emulator/test/socket_SUITE.erl index 1026b83b57..b63a6fc526 100644 --- a/erts/emulator/test/socket_SUITE.erl +++ b/erts/emulator/test/socket_SUITE.erl @@ -85,7 +85,7 @@ api_a_sendto_and_recvfrom_udp4/1, api_a_sendmsg_and_recvmsg_udp4/1, api_a_send_and_recv_tcp4/1, - %% api_a_sendmsg_and_recvmsg_tcp4/1, + api_a_sendmsg_and_recvmsg_tcp4/1, %% *** API Options *** api_opt_simple_otp_options/1, @@ -671,8 +671,8 @@ api_async_cases() -> [ api_a_sendto_and_recvfrom_udp4, api_a_sendmsg_and_recvmsg_udp4, - api_a_send_and_recv_tcp4%%, - %% api_a_sendmsg_and_recvmsg_tcp4 + api_a_send_and_recv_tcp4, + api_a_sendmsg_and_recvmsg_tcp4 ]. api_options_cases() -> @@ -3121,14 +3121,14 @@ api_a_send_and_recv_udp(InitState) -> %% the 'nowait' value for the Timeout argument (and await the eventual %% select message). Note that we only do this for the recv, %% since its much more difficult to "arrange" for send. -%% We *also* test async for accept +%% We *also* test async for accept. api_a_send_and_recv_tcp4(suite) -> []; api_a_send_and_recv_tcp4(doc) -> []; api_a_send_and_recv_tcp4(_Config) when is_list(_Config) -> ?TT(?SECS(10)), - tc_try(api_b_send_and_recv_tcp4, + tc_try(api_a_send_and_recv_tcp4, fun() -> Send = fun(Sock, Data) -> socket:send(Sock, Data) @@ -3146,6 +3146,44 @@ api_a_send_and_recv_tcp4(_Config) when is_list(_Config) -> %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +%% Basically send and receive using the msg functions (sendmsg and recvmsg) +%% on an IPv4 TCP (stream) socket. But we try to be async. That is, we use +%% the 'nowait' value for the Timeout argument (and await the eventual +%% select message). Note that we only do this for the recvmsg, +%% since its much more difficult to "arrange" for sendmsg. +%% We *also* test async for accept. +api_a_sendmsg_and_recvmsg_tcp4(suite) -> + []; +api_a_sendmsg_and_recvmsg_tcp4(doc) -> + []; +api_a_sendmsg_and_recvmsg_tcp4(_Config) when is_list(_Config) -> + ?TT(?SECS(10)), + tc_try(api_a_sendmsg_and_recvmsg_tcp4, + fun() -> + Send = fun(Sock, Data) -> + MsgHdr = #{iov => [Data]}, + socket:sendmsg(Sock, MsgHdr) + end, + Recv = fun(Sock) -> + case socket:recvmsg(Sock, nowait) of + {ok, #{addr := undefined, + iov := [Data]}} -> + {ok, Data}; + {ok, _} = OK -> + OK; + {error, _} = ERROR -> + ERROR + end + end, + InitState = #{domain => inet, + send => Send, + recv => Recv}, + ok = api_a_send_and_recv_tcp(InitState) + end). + + +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% + api_a_send_and_recv_tcp(InitState) -> process_flag(trap_exit, true), ServerSeq = |