diff options
author | Micael Karlberg <[email protected]> | 2018-05-08 12:16:11 +0200 |
---|---|---|
committer | Micael Karlberg <[email protected]> | 2018-09-18 13:01:37 +0200 |
commit | fece5e536ba4e814bcfe5896e23c2ef979468c7b (patch) | |
tree | 8578f9855ca420fa5db2694544217a133f07e0a7 | |
parent | f7f70b94f90b1f500cb884be8ae722e1a22acf2e (diff) | |
download | otp-fece5e536ba4e814bcfe5896e23c2ef979468c7b.tar.gz otp-fece5e536ba4e814bcfe5896e23c2ef979468c7b.tar.bz2 otp-fece5e536ba4e814bcfe5896e23c2ef979468c7b.zip |
[socket-nif] More setopt
Add handling of nodelay tcp option setopt.
Added placeholder sctp options autoclose and nodelay
(since my machine does not actually have sctp installed...).
-rw-r--r-- | erts/emulator/nifs/common/socket_nif.c | 64 | ||||
-rw-r--r-- | erts/preloaded/src/socket.erl | 26 |
2 files changed, 73 insertions, 17 deletions
diff --git a/erts/emulator/nifs/common/socket_nif.c b/erts/emulator/nifs/common/socket_nif.c index 11085ddab5..9887047135 100644 --- a/erts/emulator/nifs/common/socket_nif.c +++ b/erts/emulator/nifs/common/socket_nif.c @@ -366,10 +366,14 @@ typedef union { #define SOCKET_OPT_IP_TOS 2 #define SOCKET_OPT_IP_TTL 3 -#define SOCKET_OPT_IPV6_HOPLIMIT 0 +#define SOCKET_OPT_IPV6_HOPLIMIT 12 #define SOCKET_OPT_TCP_CONGESTION 0 #define SOCKET_OPT_TCP_MAXSEG 1 +#define SOCKET_OPT_TCP_NODELAY 2 + +#define SOCKET_OPT_SCTP_AUTOCLOSE 7 +#define SOCKET_OPT_SCTP_NODELAY 22 /* =================================================================== * @@ -3344,11 +3348,13 @@ BOOLEAN_T eoptval2optval_otp(ErlNifEnv* env, { if (decode_bool(env, eVal, &valP->u.boolVal)) { valP->tag = SOCKET_OPT_VALUE_BOOL; - result = TRUE; + *opt = eOpt; + result = TRUE; } else { - result = FALSE; + valP->tag = SOCKET_OPT_VALUE_UNDEF; + *opt = -1; + result = FALSE; } - *opt = eOpt; } break; @@ -3582,14 +3588,28 @@ BOOLEAN_T eoptval2optval_tcp(ErlNifEnv* env, #endif #if defined(TCP_MAXSEG) - case SOCKET_OPT_TCP_MAXSEG: - if (!GET_INT(env, eVal, &valP->u.intVal)) { - valP->tag = SOCKET_OPT_VALUE_INT; - *opt = TCP_MAXSEG; + case SOCKET_OPT_TCP_MAXSEG: + if (!GET_INT(env, eVal, &valP->u.intVal)) { + valP->tag = SOCKET_OPT_VALUE_INT; + *opt = TCP_MAXSEG; + return TRUE; + } else { + *opt = -1; + valP->tag = SOCKET_OPT_VALUE_UNDEF; + return FALSE; + } + break; +#endif + +#if defined(TCP_NODELAY) + case SOCKET_OPT_TCP_NODELAY: + if (decode_bool(env, eVal, &valP->u.boolVal)) { + valP->tag = SOCKET_OPT_VALUE_BOOL; + *opt = TCP_NODELAY; return TRUE; } else { - *opt = -1; valP->tag = SOCKET_OPT_VALUE_UNDEF; + *opt = -1; return FALSE; } break; @@ -3636,11 +3656,29 @@ BOOLEAN_T eoptval2optval_sctp(ErlNifEnv* env, switch (eOpt) { #if defined(SCTP_AUTOCLOSE) case SOCKET_OPT_SCTP_AUTOCLOSE: - if (!GET_INT(env, eVal, &valP->u.intVal)) + if (GET_INT(env, eVal, &valP->u.intVal)) { + valP->tag = SOCKET_OPT_VALUE_INT; + *opt = SCTP_AUTOCLOSE; + return TRUE; + } else { + valP->tag = SOCKET_OPT_VALUE_UNDEF; + *opt = -1; return FALSE; // PLACEHOLDER - We should really be more informative - valP->tag = SOCKET_OPT_VALUE_INT; - *opt = SCTP_AUTOCLOSE; - return TRUE; + } + break; +#endif + +#if defined(SCTP_NODELAY) + case SOCKET_OPT_SCTP_NODELAY: + if (decode_bool(env, eVal, &valP->u.boolVal)) { + valP->tag = SOCKET_OPT_VALUE_BOOL; + *opt = SCTP_NODELAY; + return TRUE; + } else { + valP->tag = SOCKET_OPT_VALUE_UNDEF; + *opt = -1; + return FALSE; + } break; #endif diff --git a/erts/preloaded/src/socket.erl b/erts/preloaded/src/socket.erl index 1304e79c99..1c811fa11a 100644 --- a/erts/preloaded/src/socket.erl +++ b/erts/preloaded/src/socket.erl @@ -233,10 +233,11 @@ unblock_source. -type ipv6_socket_option() :: addform | - add_membership | drop_membership | + add_membership | authhdr | auth_level | checksum | + drop_membership | dstopts | esp_trans_level | esp_network_level | @@ -437,10 +438,14 @@ -define(SOCKET_OPT_IP_TOS, 2). -define(SOCKET_OPT_IP_TTL, 3). --define(SOCKET_OPT_IPV6_HOPLIMIT, 0). +-define(SOCKET_OPT_IPV6_HOPLIMIT, 12). -define(SOCKET_OPT_TCP_CONGESTION, 0). -define(SOCKET_OPT_TCP_MAXSEG, 1). +-define(SOCKET_OPT_TCP_NODELAY, 2). + +-define(SOCKET_OPT_SCTP_AUTOCLOSE, 7). +-define(SOCKET_OPT_SCTP_NODELAY, 22). -define(SOCKET_SHUTDOWN_HOW_READ, 0). -define(SOCKET_SHUTDOWN_HOW_WRITE, 1). @@ -1654,6 +1659,15 @@ enc_setopt_value(tcp = L, Opt, V, _D, _T, _P) -> enc_setopt_value(udp = L, Opt, _V, _D, _T, _P) -> not_supported({L, Opt}); +enc_setopt_value(sctp, autoclose, V, _D, _T, P) + when is_integer(V) andalso + (P =:= sctp) -> + V; +enc_setopt_value(sctp, nodelay, V, _D, _T, P) + when is_boolean(V) andalso + (P =:= sctp) -> + V; + enc_setopt_value(L, Opt, V, _, _, _) when is_integer(L) andalso is_integer(Opt) andalso is_binary(V) -> V. @@ -1920,8 +1934,8 @@ enc_sockopt_key(tcp, congestion = _Opt, _Dir, _D, _T, _P) -> ?SOCKET_OPT_TCP_CONGESTION; enc_sockopt_key(tcp, maxseg = _Opt, _Dir, _D, _T, _P) -> ?SOCKET_OPT_TCP_MAXSEG; -enc_sockopt_key(tcp, nodelay = Opt, _Dir, _D, _T, _P) -> - not_supported(Opt); +enc_sockopt_key(tcp, nodelay = _Opt, _Dir, _D, _T, _P) -> + ?SOCKET_OPT_TCP_NODELAY; enc_sockopt_key(tcp, UnknownOpt, _Dir, _D, _T, _P) -> unknown(UnknownOpt); @@ -1930,6 +1944,10 @@ enc_sockopt_key(udp, UnknownOpt, _Dir, _D, _T, _P) -> unknown(UnknownOpt); %% SCTP socket options +enc_sockopt_key(sctp, autoclose = _Opt, _Dir, _D, _T, _P) -> + ?SOCKET_OPT_SCTP_AUTOCLOSE; +enc_sockopt_key(sctp, nodelay = _Opt, _Dir, _D, _T, _P) -> + ?SOCKET_OPT_SCTP_NODELAY; enc_sockopt_key(sctp, UnknownOpt, _Dir, _D, _T, _P) -> unknown(UnknownOpt); |