aboutsummaryrefslogtreecommitdiffstats
path: root/lib
diff options
context:
space:
mode:
authorMicael Karlberg <[email protected]>2018-09-19 18:21:47 +0200
committerMicael Karlberg <[email protected]>2018-09-19 18:22:41 +0200
commite01a856c993b55c3fbc76fd429783d4aad5bfc80 (patch)
tree5f379d3d987703295133a6489bbbe97ac5a1f9b7 /lib
parenta866bd04c5ce5f418f0e11685713af2992ef0ce8 (diff)
downloadotp-e01a856c993b55c3fbc76fd429783d4aad5bfc80.tar.gz
otp-e01a856c993b55c3fbc76fd429783d4aad5bfc80.tar.bz2
otp-e01a856c993b55c3fbc76fd429783d4aad5bfc80.zip
[socket-nif] Add proper connect and accept timeout handling
Added proper connect and accept timeout handling. Made use of the enif_select(mode = cancel) feature. Each time a timeout expires, the previous operation (connect or accept) has to be cancelled (actually its the select operation that has to be cancelled). Only partial implementation of cancel for now (connect and accept). More to follow... OTP-14831
Diffstat (limited to 'lib')
-rw-r--r--lib/kernel/test/socket_client.erl21
-rw-r--r--lib/kernel/test/socket_server.erl10
2 files changed, 25 insertions, 6 deletions
diff --git a/lib/kernel/test/socket_client.erl b/lib/kernel/test/socket_client.erl
index 58d70b6181..6cd353fd07 100644
--- a/lib/kernel/test/socket_client.erl
+++ b/lib/kernel/test/socket_client.erl
@@ -74,7 +74,7 @@ start(Domain, Type, Proto, Addr, Port) ->
%% The way we use tos only works because we
%% send so few messages (a new value for every
%% message).
- put(tos, 1),
+ tos_init(),
do_start(Domain, Type, Proto, SA).
do_start(Domain, stream = Type, Proto, SA) ->
@@ -282,11 +282,10 @@ send(#client{socket = Sock, type = dgram, dest = Dest}, Msg) ->
%% i("try send to: "
%% "~n ~p", [Dest]),
%% ok = socket:setopt(Sock, otp, debug, true),
- TOS = get(tos),
+ TOS = tos_next(),
ok = socket:setopt(Sock, ip, tos, TOS),
case socket:sendto(Sock, Msg, Dest) of
ok = OK ->
- put(tos, TOS+1),
OK;
{error, _} = ERROR ->
ERROR
@@ -402,6 +401,22 @@ which_addr2(Domain, [_|IFO]) ->
%% ---
+tos_init() ->
+ put(tos, 1).
+
+tos_next() ->
+ case get(tos) of
+ TOS when (TOS < 100) ->
+ put(tos, TOS + 1),
+ TOS;
+ _ ->
+ put(tos, 1),
+ 1
+ end.
+
+
+%% ---
+
e(F, A) ->
?LIB:e(F, A).
diff --git a/lib/kernel/test/socket_server.erl b/lib/kernel/test/socket_server.erl
index ea2bdc8e0d..3e5c4e5d95 100644
--- a/lib/kernel/test/socket_server.erl
+++ b/lib/kernel/test/socket_server.erl
@@ -34,7 +34,7 @@
-define(LIB, socket_lib).
-record(manager, {socket, msg, peek, acceptors, handler_id, handlers}).
--record(acceptor, {id, socket, manager}).
+-record(acceptor, {id, socket, manager, atimeout = 5000}).
-record(handler, {socket, peek, msg, type, manager}).
-define(NUM_ACCEPTORS, 5).
@@ -521,13 +521,14 @@ acceptor_stop(Pid, _Reason) ->
acceptor_init(Manager, Sock, ID) ->
put(sname, f("acceptor[~w]", [ID])),
Manager ! {acceptor, self(), ok},
+ %% ok = socket:setopt(Sock, otp, debug, true),
acceptor_loop(#acceptor{id = ID,
manager = Manager,
socket = Sock}).
-acceptor_loop(#acceptor{socket = LSock} = A) ->
+acceptor_loop(#acceptor{socket = LSock, atimeout = Timeout} = A) ->
i("try accept"),
- case socket:accept(LSock, infinity) of
+ case socket:accept(LSock, Timeout) of
{ok, Sock} ->
i("accepted: "
"~n ~p"
@@ -542,6 +543,9 @@ acceptor_loop(#acceptor{socket = LSock} = A) ->
socket:close(Sock),
exit({failed_starting_handler, Reason})
end;
+ {error, timeout} ->
+ i("timeout"),
+ acceptor_loop(A);
{error, Reason} ->
e("accept failure: "
"~n ~p", [Reason]),