aboutsummaryrefslogtreecommitdiffstats
path: root/erts/emulator
diff options
context:
space:
mode:
authorMicael Karlberg <[email protected]>2019-05-13 13:07:55 +0200
committerMicael Karlberg <[email protected]>2019-05-29 13:47:40 +0200
commit80e72ee3ddf73119618277c05df724b01ffdf18a (patch)
treee248bafc90302cb45ee5eee2ae3f9052846b6988 /erts/emulator
parent39e137878aa5d1f745cf3c343429fe9de47ed1be (diff)
downloadotp-80e72ee3ddf73119618277c05df724b01ffdf18a.tar.gz
otp-80e72ee3ddf73119618277c05df724b01ffdf18a.tar.bz2
otp-80e72ee3ddf73119618277c05df724b01ffdf18a.zip
[esock|test] Add (stream) sendmsg and recvmsg test case for local
Add a sendmsg and recvmsg test case for a unix domain (stream) socket. Found and fixed a bug for the return value for the address field for family 'local' (encoded as 'inet'). OTP-15822
Diffstat (limited to 'erts/emulator')
-rw-r--r--erts/emulator/nifs/common/socket_nif.c2
-rw-r--r--erts/emulator/nifs/common/socket_util.c2
-rw-r--r--erts/emulator/test/socket_SUITE.erl41
3 files changed, 41 insertions, 4 deletions
diff --git a/erts/emulator/nifs/common/socket_nif.c b/erts/emulator/nifs/common/socket_nif.c
index 7484694cdb..d8203f3b91 100644
--- a/erts/emulator/nifs/common/socket_nif.c
+++ b/erts/emulator/nifs/common/socket_nif.c
@@ -15180,7 +15180,7 @@ char* encode_msghdr(ErlNifEnv* env,
"\r\n read: %d"
"\r\n", read) );
- /* The address is not used if we are connected,
+ /* The address is not used if we are connected (unless family is 'local'),
* so check (length = 0) before we try to encodel
*/
if (msgHdrP->msg_namelen != 0) {
diff --git a/erts/emulator/nifs/common/socket_util.c b/erts/emulator/nifs/common/socket_util.c
index a61cfc75ef..4ba48afcfa 100644
--- a/erts/emulator/nifs/common/socket_util.c
+++ b/erts/emulator/nifs/common/socket_util.c
@@ -1656,7 +1656,7 @@ char* make_sockaddr_un(ErlNifEnv* env,
ERL_NIF_TERM* sa)
{
ERL_NIF_TERM keys[] = {esock_atom_family, esock_atom_path};
- ERL_NIF_TERM vals[] = {esock_atom_inet, path};
+ ERL_NIF_TERM vals[] = {esock_atom_local, path};
unsigned int numKeys = sizeof(keys) / sizeof(ERL_NIF_TERM);
unsigned int numVals = sizeof(vals) / sizeof(ERL_NIF_TERM);
diff --git a/erts/emulator/test/socket_SUITE.erl b/erts/emulator/test/socket_SUITE.erl
index 639dfcd14d..d4e0d104e3 100644
--- a/erts/emulator/test/socket_SUITE.erl
+++ b/erts/emulator/test/socket_SUITE.erl
@@ -77,6 +77,7 @@
api_b_send_and_recv_tcp4/1,
api_b_send_and_recv_tcpL/1,
api_b_sendmsg_and_recvmsg_tcp4/1,
+ api_b_sendmsg_and_recvmsg_tcpL/1,
%% *** API Options ***
api_opt_simple_otp_options/1,
@@ -597,7 +598,8 @@ api_basic_cases() ->
api_b_sendmsg_and_recvmsg_udp4,
api_b_send_and_recv_tcp4,
api_b_send_and_recv_tcpL,
- api_b_sendmsg_and_recvmsg_tcp4
+ api_b_sendmsg_and_recvmsg_tcp4,
+ api_b_sendmsg_and_recvmsg_tcpL
].
api_options_cases() ->
@@ -1913,6 +1915,41 @@ api_b_sendmsg_and_recvmsg_tcp4(_Config) when is_list(_Config) ->
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+%% Basically send and receive using the msg functions (sendmsg and recvmsg)
+%% on an IPv4 TCP (stream) socket.
+api_b_sendmsg_and_recvmsg_tcpL(suite) ->
+ [];
+api_b_sendmsg_and_recvmsg_tcpL(doc) ->
+ [];
+api_b_sendmsg_and_recvmsg_tcpL(_Config) when is_list(_Config) ->
+ ?TT(?SECS(10)),
+ tc_try(api_b_sendmsg_and_recvmsg_tcpL,
+ fun() -> supports_unix_domain_socket() end,
+ fun() ->
+ Send = fun(Sock, Data) ->
+ MsgHdr = #{iov => [Data]},
+ socket:sendmsg(Sock, MsgHdr)
+ end,
+ Recv = fun(Sock) ->
+ case socket:recvmsg(Sock) of
+ {ok, #{addr := #{family := local},
+ iov := [Data]}} ->
+ {ok, Data};
+ {error, _} = ERROR ->
+ ERROR
+ end
+ end,
+ InitState = #{domain => local,
+ type => stream,
+ proto => default,
+ send => Send,
+ recv => Recv},
+ ok = api_b_send_and_recv_tcp(InitState)
+ end).
+
+
+%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+
api_b_send_and_recv_tcp(InitState) ->
process_flag(trap_exit, true),
ServerSeq =
@@ -2181,7 +2218,7 @@ api_b_send_and_recv_tcp(InitState) ->
ok
end,
ok;
- (#{sock := Sock} = S) ->
+ (#{sock := Sock} = _S) ->
socket:close(Sock)
end},