diff options
author | Micael Karlberg <[email protected]> | 2018-05-08 15:45:48 +0200 |
---|---|---|
committer | Micael Karlberg <[email protected]> | 2018-09-18 13:01:37 +0200 |
commit | 0f2b8a76edaa462fca388a55eaf449a36296820a (patch) | |
tree | d2ec1f07e9a9d93329b88137ca34c5b2d39d4bd8 | |
parent | 3d719906dd0ad8d07547c3a20a2190a416dda364 (diff) | |
download | otp-0f2b8a76edaa462fca388a55eaf449a36296820a.tar.gz otp-0f2b8a76edaa462fca388a55eaf449a36296820a.tar.bz2 otp-0f2b8a76edaa462fca388a55eaf449a36296820a.zip |
[socket-nif] setopt of socket option broadcast
-rw-r--r-- | erts/emulator/nifs/common/socket_nif.c | 20 | ||||
-rw-r--r-- | erts/preloaded/src/socket.erl | 7 |
2 files changed, 25 insertions, 2 deletions
diff --git a/erts/emulator/nifs/common/socket_nif.c b/erts/emulator/nifs/common/socket_nif.c index d8e274341f..f9727d41b1 100644 --- a/erts/emulator/nifs/common/socket_nif.c +++ b/erts/emulator/nifs/common/socket_nif.c @@ -359,6 +359,7 @@ typedef union { #define SOCKET_OPT_OTP_DEBUG 0 #define SOCKET_OPT_OTP_IOW 1 +#define SOCKET_OPT_SOCK_BROADCAST 4 #define SOCKET_OPT_SOCK_DONTROUTE 7 #define SOCKET_OPT_SOCK_KEEPALIVE 9 #define SOCKET_OPT_SOCK_LINGER 10 @@ -3398,6 +3399,25 @@ BOOLEAN_T eoptval2optval_socket(ErlNifEnv* env, SocketOptValue* valP) { switch (eOpt) { +#if defined(SO_BROADCAST) + case SOCKET_OPT_SOCK_BROADCAST: + { + BOOLEAN_T val; + + if (decode_bool(env, eVal, &val)) { + *opt = SO_BROADCAST; + valP->tag = SOCKET_OPT_VALUE_INT; + valP->u.intVal = (val) ? 1 : 0; + return TRUE; + } else { + *opt = -1; + valP->tag = SOCKET_OPT_VALUE_UNDEF; + return FALSE; + } + } + break; +#endif + #if defined(SO_DONTROUTE) case SOCKET_OPT_SOCK_DONTROUTE: { diff --git a/erts/preloaded/src/socket.erl b/erts/preloaded/src/socket.erl index f1b5623362..f40fd81d36 100644 --- a/erts/preloaded/src/socket.erl +++ b/erts/preloaded/src/socket.erl @@ -432,6 +432,7 @@ -define(SOCKET_OPT_OTP_DEBUG, 0). -define(SOCKET_OPT_OTP_IOW, 1). +-define(SOCKET_OPT_SOCK_BROADCAST, 4). -define(SOCKET_OPT_SOCK_DONTROUTE, 7). -define(SOCKET_OPT_SOCK_KEEPALIVE, 9). -define(SOCKET_OPT_SOCK_LINGER, 10). @@ -1610,6 +1611,8 @@ enc_setopt_value(otp, iow, V, _, _, _) when is_boolean(V) -> enc_setopt_value(otp = L, Opt, V, _D, _T, _P) -> not_supported({L, Opt, V}); +enc_setopt_value(socket, broadcast, V, _D, _T, _P) when is_boolean(V) -> + V; enc_setopt_value(socket, keepalive, V, _D, _T, _P) when is_boolean(V) -> V; enc_setopt_value(socket, linger, abort, D, T, P) -> @@ -1798,8 +1801,8 @@ enc_sockopt_key(socket, acceptfilter = Opt, _Dir, _D, _T, _P) -> %% So, we let the implementation decide. enc_sockopt_key(socket, bindtodevide = Opt, _Dir, _D, _T, _P) -> not_supported(Opt); -enc_sockopt_key(socket, broadcast = Opt, _Dir, _D, dgram = _T, _P) -> - not_supported(Opt); +enc_sockopt_key(socket, broadcast = _Opt, _Dir, _D, dgram = _T, _P) -> + ?SOCKET_OPT_SOCK_BROADCAST; enc_sockopt_key(socket, busy_poll = Opt, _Dir, _D, _T, _P) -> not_supported(Opt); enc_sockopt_key(socket, debug = Opt, _Dir, _D, _T, _P) -> |