diff options
author | Raimo Niskanen <raimo@erlang.org> | 2020-01-09 17:01:59 +0100 |
---|---|---|
committer | Raimo Niskanen <raimo@erlang.org> | 2020-01-23 17:26:26 +0100 |
commit | ac4c222f96c4d24b7939be7209d8aed0abf1eb83 (patch) | |
tree | 24335eeba1d3838e08008d24a23ec55a7d79f13a /erts/preloaded/src/socket.erl | |
parent | 8a577a4682f8b050f3d0dc0433b331db5bf57b4d (diff) | |
download | erlang-ac4c222f96c4d24b7939be7209d8aed0abf1eb83.tar.gz |
Fix close and abort handling
Diffstat (limited to 'erts/preloaded/src/socket.erl')
-rw-r--r-- | erts/preloaded/src/socket.erl | 35 |
1 files changed, 23 insertions, 12 deletions
diff --git a/erts/preloaded/src/socket.erl b/erts/preloaded/src/socket.erl index dc6085eb52..50e1f82cb2 100644 --- a/erts/preloaded/src/socket.erl +++ b/erts/preloaded/src/socket.erl @@ -1679,10 +1679,10 @@ send_common(SockRef, Data, To, EFlags, Deadline, SendName) -> SockRef, Data, To, EFlags, Deadline, SendName); {?ESOCK_TAG, _Socket, abort, {SendRef, Reason}} -> - {error, Reason} + {error, {Reason, size(Data)}} after Timeout -> - cancel(SockRef, SendName, SendRef), + _ = cancel(SockRef, SendName, SendRef), {error, {timeout, size(Data)}} end; @@ -1707,10 +1707,10 @@ send_common(SockRef, Data, To, EFlags, Deadline, SendName) -> SockRef, Data, To, EFlags, Deadline, SendName); {?ESOCK_TAG, _Socket, abort, {SendRef, Reason}} -> - {error, Reason} + {error, {Reason, size(Data)}} after Timeout -> - cancel(SockRef, SendName, SendRef), + _ = cancel(SockRef, SendName, SendRef), {error, {timeout, size(Data)}} end; @@ -1720,8 +1720,6 @@ send_common(SockRef, Data, To, EFlags, Deadline, SendName) -> end. - - %% --------------------------------------------------------------------------- %% @@ -1901,7 +1899,7 @@ do_sendmsg(SockRef, MsgHdr, EFlags, Deadline) -> %% %% We need to cancel this partial write. %% - cancel(SockRef, sendmsg, SendRef), + _ = cancel(SockRef, sendmsg, SendRef), {ok, do_sendmsg_rest(maps:get(iov, MsgHdr), Written)}; @@ -1921,10 +1919,13 @@ do_sendmsg(SockRef, MsgHdr, EFlags, Deadline) -> Timeout = timeout(Deadline), receive {?ESOCK_TAG, #socket{ref = SockRef}, select, SendRef} -> - do_sendmsg(SockRef, MsgHdr, EFlags, Deadline) + do_sendmsg(SockRef, MsgHdr, EFlags, Deadline); + + {?ESOCK_TAG, _Socket, abort, {SendRef, Reason}} -> + {error, Reason} after Timeout -> - cancel(SockRef, sendmsg, SendRef), + _ = cancel(SockRef, sendmsg, SendRef), {error, timeout} end; @@ -3909,19 +3910,29 @@ cancel(SockRef, Op, OpRef) -> case nif_cancel(SockRef, Op, OpRef) of %% The select has already completed {error, select_sent} -> - flush_select_msgs(SockRef, OpRef); + flush_select_msg(SockRef, OpRef), + _ = flush_abort_msg(SockRef, OpRef), + ok; Other -> + _ = flush_abort_msg(SockRef, OpRef), Other end. -flush_select_msgs(SockRef, Ref) -> +flush_select_msg(SockRef, Ref) -> receive {?ESOCK_TAG, #socket{ref = SockRef}, select, Ref} -> - flush_select_msgs(SockRef, Ref) + ok after 0 -> ok end. +flush_abort_msg(SockRef, Ref) -> + receive + {?ESOCK_TAG, #socket{ref = SockRef}, abort, {Ref, Reason}} -> + Reason + after 0 -> + ok + end. %% formated_timestamp() -> %% format_timestamp(os:timestamp()). |