diff options
author | Micael Karlberg <[email protected]> | 2018-10-05 14:52:47 +0200 |
---|---|---|
committer | Micael Karlberg <[email protected]> | 2018-10-05 14:52:47 +0200 |
commit | 6e931258872c15404aa1dfd5198f2b490452b30b (patch) | |
tree | 5ca9404bc26eb9d734bfa8cd16372cc447a7be5a /erts | |
parent | 4e3f42da1dae7166faeb9f9e07adc40bc3b22d75 (diff) | |
download | otp-6e931258872c15404aa1dfd5198f2b490452b30b.tar.gz otp-6e931258872c15404aa1dfd5198f2b490452b30b.tar.bz2 otp-6e931258872c15404aa1dfd5198f2b490452b30b.zip |
[socket-nif] Add *preliminary* new function supports/0,1
Diffstat (limited to 'erts')
-rw-r--r-- | erts/emulator/nifs/common/socket_nif.c | 37 | ||||
-rw-r--r-- | erts/preloaded/src/socket.erl | 14 |
2 files changed, 48 insertions, 3 deletions
diff --git a/erts/emulator/nifs/common/socket_nif.c b/erts/emulator/nifs/common/socket_nif.c index 0ef88162bc..4def45f869 100644 --- a/erts/emulator/nifs/common/socket_nif.c +++ b/erts/emulator/nifs/common/socket_nif.c @@ -860,6 +860,9 @@ typedef struct { static ERL_NIF_TERM nif_info(ErlNifEnv* env, int argc, const ERL_NIF_TERM argv[]); +static ERL_NIF_TERM nif_supports(ErlNifEnv* env, + int argc, + const ERL_NIF_TERM argv[]); /* This is a *global* debug function (enable or disable for all operations and all sockets. @@ -2536,6 +2539,7 @@ static SocketData data; * Utility and admin functions: * ---------------------------- * nif_info/0 + * nif_supports/1 * (nif_debug/1) * * The "proper" socket functions: @@ -2619,6 +2623,31 @@ ERL_NIF_TERM nif_info(ErlNifEnv* env, } + +/* ---------------------------------------------------------------------- + * nif_supports + * + * Description: + * This function is intended to answer the question: "Is X supported?" + * Currently only one key is "supported": options + * That results in a list of all *known options* (known by us) and if + * the platform supports (OS) it or not. + */ + +static +ERL_NIF_TERM nif_support(ErlNifEnv* env, + int argc, + const ERL_NIF_TERM argv[]) +{ + if (argc != 1) { + return enif_make_badarg(env); + } else { + return MKEL(env); // PLACEHOLDER + } +} + + + /* ---------------------------------------------------------------------- * nif_open * @@ -15412,9 +15441,11 @@ void socket_down_reader(ErlNifEnv* env, static ErlNifFunc socket_funcs[] = { - // Some utility functions - {"nif_info", 0, nif_info, 0}, - // {"nif_debug", 1, nif_debug_, 0}, + // Some utility and support functions + {"nif_info", 0, nif_info, 0}, + {"nif_supports", 1, nif_supports, 0}, + // {"nif_debug", 1, nif_debug, 0}, + // {"nif_command", 1, nif_command, 0}, // The proper "socket" interface // nif_open/1 is used when we already have a file descriptor diff --git a/erts/preloaded/src/socket.erl b/erts/preloaded/src/socket.erl index c388fc2849..147d074310 100644 --- a/erts/preloaded/src/socket.erl +++ b/erts/preloaded/src/socket.erl @@ -27,6 +27,7 @@ -export([ on_load/0, on_load/1, info/0, + supports/0, supports/1, ensure_sockaddr/1 ]). @@ -843,6 +844,16 @@ info() -> nif_info(). +-spec supports() -> list(). + +supports() -> + [{options, supports(options)}]. + +supports(options) -> + nif_supports(?SOCKET_SUPPORTS_OPTIONS); +supports(_) -> + false. + %% =========================================================================== %% @@ -3417,6 +3428,9 @@ error(Reason) -> nif_info() -> erlang:nif_error(undef). +nif_supports(_Key) -> + erlang:nif_error(undef). + nif_open(_Domain, _Type, _Protocol, _Extra) -> erlang:nif_error(undef). |