aboutsummaryrefslogtreecommitdiffstats
path: root/erts/preloaded
diff options
context:
space:
mode:
authorMicael Karlberg <[email protected]>2018-12-12 18:37:55 +0100
committerMicael Karlberg <[email protected]>2018-12-14 11:46:28 +0100
commit342d35f457c15a9cea426e8ca83bfd52b0ec2f2e (patch)
treee4e98ea22598735af6972f5721195b80f0afe273 /erts/preloaded
parenta33acd53524160d65929d06f06e387ce8419b1c0 (diff)
downloadotp-342d35f457c15a9cea426e8ca83bfd52b0ec2f2e.tar.gz
otp-342d35f457c15a9cea426e8ca83bfd52b0ec2f2e.tar.bz2
otp-342d35f457c15a9cea426e8ca83bfd52b0ec2f2e.zip
[socket-nif] Message interface between socket.erl and nif updated
Previously the "message interface" between the functions in socket.erl and the nif-code (socket_nif.c) was "ad hoc". This has now been changed so that we have a unified message {'$socket', SockRef | undefined, Tag, Info} This also has the added advantage of preparing the code for when we start using the new select-fucntions (with which its possible to specify your own message). This will be used in order to get around our eterm "leak" (we will use a simple counter, maintained in the nif, instead of the [Recv|Send|Acc]Ref we generate in the erlang code today. OTP-14831
Diffstat (limited to 'erts/preloaded')
-rw-r--r--erts/preloaded/ebin/socket.beambin69392 -> 70272 bytes
-rw-r--r--erts/preloaded/src/socket.erl34
2 files changed, 19 insertions, 15 deletions
diff --git a/erts/preloaded/ebin/socket.beam b/erts/preloaded/ebin/socket.beam
index 25046e6aad..ddd50fdefa 100644
--- a/erts/preloaded/ebin/socket.beam
+++ b/erts/preloaded/ebin/socket.beam
Binary files differ
diff --git a/erts/preloaded/src/socket.erl b/erts/preloaded/src/socket.erl
index a40692881b..2e295a91ae 100644
--- a/erts/preloaded/src/socket.erl
+++ b/erts/preloaded/src/socket.erl
@@ -1331,7 +1331,7 @@ do_accept(LSockRef, Timeout) ->
{select, LSockRef, AccRef, ready_input} ->
do_accept(LSockRef, next_timeout(TS, Timeout));
- {nif_abort, AccRef, Reason} ->
+ {'$socket', _, abort, {AccRef, Reason}} ->
{error, Reason}
after NewTimeout ->
@@ -1408,7 +1408,7 @@ do_send(SockRef, Data, EFlags, Timeout) ->
do_send(SockRef, Data, EFlags,
next_timeout(TS, Timeout));
- {nif_abort, SendRef, Reason} ->
+ {'$socket', _, abort, {SendRef, Reason}} ->
{error, Reason}
after NewTimeout ->
@@ -1421,7 +1421,7 @@ do_send(SockRef, Data, EFlags, Timeout) ->
do_send(SockRef, Data, EFlags,
next_timeout(TS, Timeout));
- {nif_abort, SendRef, Reason} ->
+ {'$socket', _, abort, {SendRef, Reason}} ->
{error, Reason}
after Timeout ->
@@ -1513,7 +1513,7 @@ do_sendto(SockRef, Data, Dest, EFlags, Timeout) ->
do_sendto(SockRef, Data, Dest, EFlags,
next_timeout(TS, Timeout));
- {nif_abort, SendRef, Reason} ->
+ {'$socket', _, abort, {SendRef, Reason}} ->
{error, Reason}
after Timeout ->
@@ -1525,7 +1525,11 @@ do_sendto(SockRef, Data, Dest, EFlags, Timeout) ->
receive
{select, SockRef, SendRef, ready_output} ->
do_sendto(SockRef, Data, Dest, EFlags,
- next_timeout(TS, Timeout))
+ next_timeout(TS, Timeout));
+
+ {'$socket', _, abort, {SendRef, Reason}} ->
+ {error, Reason}
+
after Timeout ->
cancel(SockRef, sendto, SendRef),
{error, timeout}
@@ -1773,10 +1777,9 @@ do_recv(SockRef, _OldRef, Length, EFlags, Acc, Timeout)
Bin,
next_timeout(TS, Timeout));
- {nif_abort, RecvRef, Reason} ->
+ {'$socket', _, abort, {RecvRef, Reason}} ->
{error, Reason}
-
after NewTimeout ->
cancel(SockRef, recv, RecvRef),
{error, {timeout, Acc}}
@@ -1794,10 +1797,9 @@ do_recv(SockRef, _OldRef, Length, EFlags, Acc, Timeout)
<<Acc/binary, Bin/binary>>,
next_timeout(TS, Timeout));
- {nif_abort, RecvRef, Reason} ->
+ {'$socket', _, abort, {RecvRef, Reason}} ->
{error, Reason}
-
after NewTimeout ->
cancel(SockRef, recv, RecvRef),
{error, {timeout, Acc}}
@@ -1805,6 +1807,7 @@ do_recv(SockRef, _OldRef, Length, EFlags, Acc, Timeout)
%% We return with the accumulated binary (if its non-empty)
{error, eagain} when (Length =:= 0) andalso (size(Acc) > 0) ->
+ %% CAN WE REALLY DO THIS? THE NIF HAS SELECTED!! OR?
{ok, Acc};
{error, eagain} ->
@@ -1819,7 +1822,7 @@ do_recv(SockRef, _OldRef, Length, EFlags, Acc, Timeout)
Acc,
next_timeout(TS, Timeout));
- {nif_abort, RecvRef, Reason} ->
+ {'$socket', _, abort, {RecvRef, Reason}} ->
{error, Reason}
after NewTimeout ->
@@ -1850,7 +1853,8 @@ do_recv(SockRef, RecvRef, 0 = _Length, _Eflags, Acc, _Timeout) ->
%% any waiting reader.
cancel(SockRef, recv, RecvRef),
{ok, Acc};
-do_recv(_SockRef, _RecvRef, _Length, _EFlags, Acc, _Timeout) when (size(Acc) > 0) ->
+do_recv(_SockRef, _RecvRef, _Length, _EFlags, Acc, _Timeout)
+ when (size(Acc) > 0) ->
{error, {timeout, Acc}};
do_recv(_SockRef, _RecvRef, _Length, _EFlags, _Acc, _Timeout) ->
{error, timeout}.
@@ -1957,8 +1961,7 @@ do_recvfrom(SockRef, BufSz, EFlags, Timeout) ->
do_recvfrom(SockRef, BufSz, EFlags,
next_timeout(TS, Timeout));
- {nif_abort, RecvRef, Reason} ->
- %% p("received nif-abort: ~p", [Reason]),
+ {'$socket', _, abort, {RecvRef, Reason}} ->
{error, Reason}
after NewTimeout ->
@@ -2062,7 +2065,7 @@ do_recvmsg(SockRef, BufSz, CtrlSz, EFlags, Timeout) ->
do_recvmsg(SockRef, BufSz, CtrlSz, EFlags,
next_timeout(TS, Timeout));
- {nif_abort, RecvRef, Reason} ->
+ {'$socket', _, abort, {RecvRef, Reason}} ->
{error, Reason}
after NewTimeout ->
@@ -2107,7 +2110,8 @@ do_close(SockRef) ->
{ok, CloseRef} ->
%% We must wait
receive
- {close, CloseRef} ->
+ {'$socket', _, close, CloseRef} ->
+%% {close, CloseRef} ->
%% <KOLLA>
%%
%% WHAT HAPPENS IF THIS PROCESS IS KILLED