aboutsummaryrefslogtreecommitdiffstats
path: root/erts/preloaded
diff options
context:
space:
mode:
authorLukas Larsson <[email protected]>2013-10-07 17:24:11 +0200
committerLukas Larsson <[email protected]>2013-10-07 17:24:11 +0200
commit5ee95f1f10f879a9caec67248c27e74dacbf276d (patch)
tree42dc7c80174154357373c1ba9e614d15dc2c8bf7 /erts/preloaded
parent036727ce61cfbd51ece3d20a07d33c10c035ecec (diff)
parent1e6c600111fac2cf564bcdfab0230ffd70cb30c3 (diff)
downloadotp-5ee95f1f10f879a9caec67248c27e74dacbf276d.tar.gz
otp-5ee95f1f10f879a9caec67248c27e74dacbf276d.tar.bz2
otp-5ee95f1f10f879a9caec67248c27e74dacbf276d.zip
Merge branch 'sv-socket-active-n'
OTP-11368 * sv-socket-active-n: Update preloaded add {active,N} socket option for TCP, UDP, and SCTP
Diffstat (limited to 'erts/preloaded')
-rw-r--r--erts/preloaded/ebin/prim_inet.beambin70908 -> 71452 bytes
-rw-r--r--erts/preloaded/src/prim_inet.erl20
2 files changed, 16 insertions, 4 deletions
diff --git a/erts/preloaded/ebin/prim_inet.beam b/erts/preloaded/ebin/prim_inet.beam
index 2be5ae1d96..deed86816e 100644
--- a/erts/preloaded/ebin/prim_inet.beam
+++ b/erts/preloaded/ebin/prim_inet.beam
Binary files differ
diff --git a/erts/preloaded/src/prim_inet.erl b/erts/preloaded/src/prim_inet.erl
index fa621681f3..69eed716ff 100644
--- a/erts/preloaded/src/prim_inet.erl
+++ b/erts/preloaded/src/prim_inet.erl
@@ -1237,7 +1237,8 @@ type_opt_1(buffer) -> int;
type_opt_1(active) ->
{enum,[{false, ?INET_PASSIVE},
{true, ?INET_ACTIVE},
- {once, ?INET_ONCE}]};
+ {once, ?INET_ONCE},
+ {multi, ?INET_MULTI}]};
type_opt_1(packet) ->
{enum,[{0, ?TCP_PB_RAW},
{1, ?TCP_PB_1},
@@ -1716,11 +1717,14 @@ encode_opt_val(Opts) ->
Reason -> {error,Reason}
end.
+%% {active, once} and {active, N} are specially optimized because they will
+%% be used for every packet or every N packets, not only once when
+%% initializing the socket. Measurements show that this optimization is
+%% worthwhile.
enc_opt_val([{active,once}|Opts], Acc) ->
- %% Specially optimized because {active,once} will be used for
- %% every packet, not only once when initializing the socket.
- %% Measurements show that this optimization is worthwhile.
enc_opt_val(Opts, [<<?INET_LOPT_ACTIVE:8,?INET_ONCE:32>>|Acc]);
+enc_opt_val([{active,N}|Opts], Acc) when is_integer(N), N < 32768, N >= -32768 ->
+ enc_opt_val(Opts, [<<?INET_LOPT_ACTIVE:8,?INET_MULTI:32,N:16>>|Acc]);
enc_opt_val([{raw,P,O,B}|Opts], Acc) ->
enc_opt_val(Opts, Acc, raw, {P,O,B});
enc_opt_val([{Opt,Val}|Opts], Acc) ->
@@ -1810,6 +1814,14 @@ dec_opt_val([]) -> [].
dec_opt_val(Buf, raw, Type) ->
{{P,O,B},T} = dec_value(Type, Buf),
[{raw,P,O,B}|dec_opt_val(T)];
+dec_opt_val(Buf, active, Type) ->
+ case dec_value(Type, Buf) of
+ {multi,[M0,M1|T]} ->
+ <<N:16>> = list_to_binary([M0,M1]),
+ [{active,N}|dec_opt_val(T)];
+ {Val,T} ->
+ [{active,Val}|dec_opt_val(T)]
+ end;
dec_opt_val(Buf, Opt, Type) ->
{Val,T} = dec_value(Type, Buf),
[{Opt,Val}|dec_opt_val(T)].