diff options
author | Micael Karlberg <[email protected]> | 2018-07-13 12:34:06 +0200 |
---|---|---|
committer | Micael Karlberg <[email protected]> | 2018-09-18 14:50:18 +0200 |
commit | 416644989e26ac76038523511d81ebf9e0b8fc4f (patch) | |
tree | d730c1ba62de3789cbdd25d9c21aca09b23694f8 /erts | |
parent | 3a2c48b2740f08d3582028fd2f8d626009aa911e (diff) | |
download | otp-416644989e26ac76038523511d81ebf9e0b8fc4f.tar.gz otp-416644989e26ac76038523511d81ebf9e0b8fc4f.tar.bz2 otp-416644989e26ac76038523511d81ebf9e0b8fc4f.zip |
[net+socket-nif] Updated on_load stuff
The net nif-module had debug on by default. Fixed this
and also made it an option, just as for the socket nif-module.
OTP-14831
Diffstat (limited to 'erts')
-rw-r--r-- | erts/emulator/nifs/common/net_nif.c | 20 | ||||
-rw-r--r-- | erts/emulator/nifs/common/socket_nif.c | 60 | ||||
-rw-r--r-- | erts/emulator/nifs/common/socket_util.c | 27 | ||||
-rw-r--r-- | erts/emulator/nifs/common/socket_util.h | 5 |
4 files changed, 75 insertions, 37 deletions
diff --git a/erts/emulator/nifs/common/net_nif.c b/erts/emulator/nifs/common/net_nif.c index 6829de509b..309ad05a36 100644 --- a/erts/emulator/nifs/common/net_nif.c +++ b/erts/emulator/nifs/common/net_nif.c @@ -209,6 +209,9 @@ # define SOCKLEN_T size_t #endif +/* Debug stuff... */ +#define NET_NIF_DEBUG_DEFAULT FALSE + #define NDBG( proto ) ESOCK_DBG_PRINTF( data.debug , proto ) @@ -331,6 +334,8 @@ static char* make_address_info(ErlNifEnv* env, ERL_NIF_TERM addr, ERL_NIF_TERM* ai); +static BOOLEAN_T extract_debug(ErlNifEnv* env, + ERL_NIF_TERM map); static int on_load(ErlNifEnv* env, void** priv_data, ERL_NIF_TERM load_info); @@ -1535,6 +1540,19 @@ ErlNifFunc net_funcs[] = }; +static +BOOLEAN_T extract_debug(ErlNifEnv* env, + ERL_NIF_TERM map) +{ + /* + * We need to do this here since the "proper" atom has not been + * created when this function is called. + */ + ERL_NIF_TERM debug = MKA(env, "debug"); + + return esock_extract_bool_from_map(env, map, debug, NET_NIF_DEBUG_DEFAULT); +} + /* ======================================================================= * load_info - A map of misc info (e.g global debug) @@ -1544,7 +1562,7 @@ static int on_load(ErlNifEnv* env, void** priv_data, ERL_NIF_TERM load_info) { // We should make it possible to use load_info to get default values - data.debug = TRUE; + data.debug = extract_debug(env, load_info); NDBG( ("NET", "on_load -> entry\r\n") ); diff --git a/erts/emulator/nifs/common/socket_nif.c b/erts/emulator/nifs/common/socket_nif.c index 1f9234016c..d973633606 100644 --- a/erts/emulator/nifs/common/socket_nif.c +++ b/erts/emulator/nifs/common/socket_nif.c @@ -1499,14 +1499,10 @@ static char* send_msg(ErlNifEnv* env, ERL_NIF_TERM msg, ErlNifPid* pid); -static BOOLEAN_T extract_debug_on_load(ErlNifEnv* env, - ERL_NIF_TERM map); -static BOOLEAN_T extract_iow_on_load(ErlNifEnv* env, - ERL_NIF_TERM map); -static BOOLEAN_T extract_bool(ErlNifEnv* env, - ERL_NIF_TERM map, - ERL_NIF_TERM ekey, - BOOLEAN_T def); +static BOOLEAN_T extract_debug(ErlNifEnv* env, + ERL_NIF_TERM map); +static BOOLEAN_T extract_iow(ErlNifEnv* env, + ERL_NIF_TERM map); static int on_load(ErlNifEnv* env, void** priv_data, ERL_NIF_TERM load_info); @@ -8423,37 +8419,29 @@ ErlNifFunc socket_funcs[] = static -BOOLEAN_T extract_debug_on_load(ErlNifEnv* env, - ERL_NIF_TERM map) +BOOLEAN_T extract_debug(ErlNifEnv* env, + ERL_NIF_TERM map) { - return extract_bool(env, map, esock_atom_debug, SOCKET_NIF_DEBUG_DEFAULT); -} - -static -BOOLEAN_T extract_iow_on_load(ErlNifEnv* env, - ERL_NIF_TERM map) -{ - return extract_bool(env, map, atom_iow, SOCKET_NIF_IOW_DEFAULT); + /* + * We need to do this here since the "proper" atom has not been + * created when this function is called. + */ + ERL_NIF_TERM debug = MKA(env, "debug"); + + return esock_extract_bool_from_map(env, map, debug, SOCKET_NIF_DEBUG_DEFAULT); } static -BOOLEAN_T extract_bool(ErlNifEnv* env, - ERL_NIF_TERM map, - ERL_NIF_TERM ekey, - BOOLEAN_T def) +BOOLEAN_T extract_iow(ErlNifEnv* env, + ERL_NIF_TERM map) { - ERL_NIF_TERM eval; - - if (!GET_MAP_VAL(env, map, ekey, &eval)) - return def; - - if (!IS_ATOM(env, eval)) - return def; - - if (COMPARE(eval, esock_atom_true) == 0) - return TRUE; - else - return FALSE; + /* + * We need to do this here since the "proper" atom has not been + * created when this function is called. + */ + ERL_NIF_TERM iow = MKA(env, "iow"); + + return esock_extract_bool_from_map(env, map, iow, SOCKET_NIF_IOW_DEFAULT); } @@ -8465,8 +8453,8 @@ BOOLEAN_T extract_bool(ErlNifEnv* env, static int on_load(ErlNifEnv* env, void** priv_data, ERL_NIF_TERM load_info) { - data.dbg = extract_debug_on_load(env, load_info); - data.iow = extract_iow_on_load(env, load_info); + data.dbg = extract_debug(env, load_info); + data.iow = extract_iow(env, load_info); /* +++ Global Counters +++ */ data.cntMtx = MCREATE("socket[gcnt]"); diff --git a/erts/emulator/nifs/common/socket_util.c b/erts/emulator/nifs/common/socket_util.c index 512c1d38e0..e6eb21adcf 100644 --- a/erts/emulator/nifs/common/socket_util.c +++ b/erts/emulator/nifs/common/socket_util.c @@ -1098,6 +1098,33 @@ BOOLEAN_T esock_decode_string(ErlNifEnv* env, +/* *** esock_extract_bool_from_map *** + * + * Extract an boolean item from a map. + * + */ +extern +BOOLEAN_T esock_extract_bool_from_map(ErlNifEnv* env, + ERL_NIF_TERM map, + ERL_NIF_TERM key, + BOOLEAN_T def) +{ + ERL_NIF_TERM val; + + if (!GET_MAP_VAL(env, map, key, &val)) + return def; + + if (!IS_ATOM(env, val)) + return def; + + if (COMPARE(val, esock_atom_true) == 0) + return TRUE; + else + return FALSE; +} + + + /* *** esock_decode_bool *** * * Decode a boolean value. diff --git a/erts/emulator/nifs/common/socket_util.h b/erts/emulator/nifs/common/socket_util.h index f1c122e281..686ce0bac6 100644 --- a/erts/emulator/nifs/common/socket_util.h +++ b/erts/emulator/nifs/common/socket_util.h @@ -133,6 +133,11 @@ BOOLEAN_T esock_decode_string(ErlNifEnv* env, char** stringP); extern +BOOLEAN_T esock_extract_bool_from_map(ErlNifEnv* env, + ERL_NIF_TERM map, + ERL_NIF_TERM key, + BOOLEAN_T def); +extern BOOLEAN_T esock_decode_bool(ERL_NIF_TERM val); extern ERL_NIF_TERM esock_encode_bool(BOOLEAN_T val); |