diff options
author | Loïc Hoguin <[email protected]> | 2019-02-16 10:25:48 +0100 |
---|---|---|
committer | Loïc Hoguin <[email protected]> | 2019-02-19 10:00:12 +0100 |
commit | 33a9c7d4c916996708694428f8b285f51c1256ff (patch) | |
tree | 06ed8f57bb13a4e3a09a25731b6096aa2d58e7a2 /lib/ssl | |
parent | 4f0b8e5eb61a2019285bfc7a8e50af1d338ffd63 (diff) | |
download | otp-33a9c7d4c916996708694428f8b285f51c1256ff.tar.gz otp-33a9c7d4c916996708694428f8b285f51c1256ff.tar.bz2 otp-33a9c7d4c916996708694428f8b285f51c1256ff.zip |
ssl: Use common fonction to update {active,N}
Diffstat (limited to 'lib/ssl')
-rw-r--r-- | lib/ssl/src/dtls_packet_demux.erl | 11 | ||||
-rw-r--r-- | lib/ssl/src/tls_socket.erl | 24 |
2 files changed, 15 insertions, 20 deletions
diff --git a/lib/ssl/src/dtls_packet_demux.erl b/lib/ssl/src/dtls_packet_demux.erl index 4945ef3c10..092366b7c0 100644 --- a/lib/ssl/src/dtls_packet_demux.erl +++ b/lib/ssl/src/dtls_packet_demux.erl @@ -298,16 +298,7 @@ do_set_emulated_opts([], Opts) -> do_set_emulated_opts([{mode, Value} | Rest], Opts) -> do_set_emulated_opts(Rest, Opts#socket_options{mode = Value}); do_set_emulated_opts([{active, N0} | Rest], Opts=#socket_options{active = Active}) when is_integer(N0) -> - N = case Active of - N1 when is_integer(N1), N0 + N1 =< 0 -> - false; - N1 when is_integer(N1) -> - N0 + N1; - _ when N0 =< 0 -> - false; - _ -> - N0 - end, + N = tls_socket:update_active_n(N0, Active), do_set_emulated_opts(Rest, Opts#socket_options{active = N}); do_set_emulated_opts([{active, Value} | Rest], Opts) -> do_set_emulated_opts(Rest, Opts#socket_options{active = Value}). diff --git a/lib/ssl/src/tls_socket.erl b/lib/ssl/src/tls_socket.erl index 9794ba39de..c3c41d3e12 100644 --- a/lib/ssl/src/tls_socket.erl +++ b/lib/ssl/src/tls_socket.erl @@ -32,6 +32,7 @@ emulated_socket_options/2, get_emulated_opts/1, set_emulated_opts/2, get_all_opts/1, handle_call/3, handle_cast/2, handle_info/2, code_change/3]). +-export([update_active_n/2]). -record(state, { emulated_opts, @@ -334,20 +335,23 @@ split_options([Name | Opts], Emu, SocketOptNames, EmuOptNames) -> do_set_emulated_opts([], Opts) -> Opts; do_set_emulated_opts([{active, N0} | Rest], Opts) when is_integer(N0) -> - N = case proplists:lookup(active, Opts) of - {_, N1} when is_integer(N1), N0 + N1 =< 0 -> - false; - {_, N1} when is_integer(N1) -> - N0 + N1; - _ when N0 =< 0 -> - false; - _ -> - N0 - end, + N = update_active_n(N0, proplists:get_value(active, Opts, false)), do_set_emulated_opts(Rest, [{active, N} | proplists:delete(active, Opts)]); do_set_emulated_opts([{Name,_} = Opt | Rest], Opts) -> do_set_emulated_opts(Rest, [Opt | proplists:delete(Name, Opts)]). +update_active_n(New, Current) -> + if + is_integer(Current), New + Current =< 0 -> + false; + is_integer(Current) -> + New + Current; + New =< 0 -> + false; + true -> + New + end. + get_socket_opts(_, [], _) -> []; get_socket_opts(ListenSocket, SockOptNames, Cb) -> |