From c1b8ff3ac77c5a4476ae980b4702dcf706903549 Mon Sep 17 00:00:00 2001 From: Micael Karlberg Date: Tue, 16 Apr 2019 10:51:31 +0200 Subject: [socket] Add nowait test case (sendmsg and recvmsg udp4) Added test case api_a_sendmsg_and_recvmsg_udp4. --- erts/emulator/test/socket_SUITE.erl | 47 ++++++++++++++++++++++++++++++++++--- 1 file changed, 44 insertions(+), 3 deletions(-) (limited to 'erts/emulator') diff --git a/erts/emulator/test/socket_SUITE.erl b/erts/emulator/test/socket_SUITE.erl index a38862dbed..4d1dca9ecc 100644 --- a/erts/emulator/test/socket_SUITE.erl +++ b/erts/emulator/test/socket_SUITE.erl @@ -83,7 +83,7 @@ %% *** API async *** api_a_sendto_and_recvfrom_udp4/1, - %% api_a_sendmsg_and_recvmsg_udp4/1, + api_a_sendmsg_and_recvmsg_udp4/1, %% api_a_send_and_recv_tcp4/1, %% api_a_sendmsg_and_recvmsg_tcp4/1, @@ -669,8 +669,8 @@ api_basic_cases() -> api_async_cases() -> [ - api_a_sendto_and_recvfrom_udp4%% , - %% api_a_sendmsg_and_recvmsg_udp4, + api_a_sendto_and_recvfrom_udp4, + api_a_sendmsg_and_recvmsg_udp4%%, %% api_a_send_and_recv_tcp4, %% api_a_sendmsg_and_recvmsg_tcp4 ]. @@ -2662,6 +2662,47 @@ api_a_sendto_and_recvfrom_udp4(_Config) when is_list(_Config) -> +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% + +%% Basically send and receive on an IPv4 UDP (dgram) socket using +%% sendto and recvfrom. 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 recvfrom, +%% since its much more difficult to "arrange" for sendto. +%% +api_a_sendmsg_and_recvmsg_udp4(suite) -> + []; +api_a_sendmsg_and_recvmsg_udp4(doc) -> + []; +api_a_sendmsg_and_recvmsg_udp4(_Config) when is_list(_Config) -> + ?TT(?SECS(5)), + tc_try(api_a_sendmsg_and_recvmsg_udp4, + fun() -> + Send = fun(Sock, Data, Dest) -> + MsgHdr = #{addr => Dest, + %% ctrl => CMsgHdrs, + iov => [Data]}, + socket:sendmsg(Sock, MsgHdr) + end, + Recv = fun(Sock) -> + case socket:recvmsg(Sock, nowait) of + {ok, #{addr := Source, + iov := [Data]}} -> + {ok, {Source, Data}}; + {ok, _} = OK -> + OK; + {error, _} = ERROR -> + ERROR + end + end, + InitState = #{domain => inet, + send => Send, + recv => Recv}, + ok = api_a_send_and_recv_udp(InitState) + end). + + + %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% api_a_send_and_recv_udp(InitState) -> -- cgit v1.2.3