From d72a3c72dc6e74fb06e4e488db32fc819ce0c088 Mon Sep 17 00:00:00 2001 From: Micael Karlberg Date: Tue, 18 Sep 2018 12:40:43 +0200 Subject: [socket-nif] Cleanup and guards Some cleanup and also added a guard to sendmsg to ensure that only ctrl (cmsg hdr) with actual content will be "sent down". OTP-14831 --- erts/preloaded/ebin/socket.beam | Bin 66000 -> 66132 bytes erts/preloaded/src/socket.erl | 19 ++----------------- 2 files changed, 2 insertions(+), 17 deletions(-) (limited to 'erts/preloaded') diff --git a/erts/preloaded/ebin/socket.beam b/erts/preloaded/ebin/socket.beam index b3f3e385d2..1100065e2a 100644 Binary files a/erts/preloaded/ebin/socket.beam and b/erts/preloaded/ebin/socket.beam differ diff --git a/erts/preloaded/src/socket.erl b/erts/preloaded/src/socket.erl index d1053d88f9..ad7a35694b 100644 --- a/erts/preloaded/src/socket.erl +++ b/erts/preloaded/src/socket.erl @@ -565,20 +565,6 @@ credentials | origdstaddr | integer(). -%% Do we need this? See cmsghdr() -%% -type cmsghdr_data() :: timeval() | % if level = socket and type = timstamp -%% ip_pktinfo() | % if level = ip and type = pktinfo -%% ipv6_pktinfo() | % if level = ipv6 and type = pktinfo -%% ip_tos() | % if level = ip and type = tos -%% integer() | % if level = ip and type = ttl -%% sockaddr_in4() | % if level = ip and type = origdstaddr -%% binary(). -%% -type cmsghdr() :: #{ -%% level := cmsghdr_level(), -%% type := cmsghdr_type(), -%% data := cmsghdr_data() -%% }. - -type cmsghdr_recv() :: #{level := socket, type := timestamp, data := timeval()} | #{level := socket, type := rights, data := binary()} | @@ -592,8 +578,6 @@ #{level := ipv6, type := pktinfo, data := ipv6_pktinfo()} | #{level := ipv6, type := integer(), data := binary()} | #{level := integer(), type := integer(), data := binary()}. - - -type cmsghdr_send() :: #{level := socket, type := integer(), data := binary()} | #{level := ip, type := tos, data := ip_tos() | binary()} | @@ -1522,9 +1506,10 @@ do_sendmsg(SockRef, MsgHdr, EFlags, Timeout) -> ERROR end. +ensure_msghdr(#{ctrl := []} = M) -> + ensure_msghdr(maps:remove(ctrl, M)); ensure_msghdr(#{iov := IOV} = M) when is_list(IOV) andalso (IOV =/= []) -> M#{iov := erlang:iolist_to_iovec(IOV)}; - %% M; ensure_msghdr(_) -> einval(). -- cgit v1.2.3