diff options
author | Micael Karlberg <[email protected]> | 2018-07-10 11:28:11 +0200 |
---|---|---|
committer | Micael Karlberg <[email protected]> | 2018-09-18 14:50:18 +0200 |
commit | 9110ba256099e6fa55461fc4ca90da5ec4b2966b (patch) | |
tree | c290bff6c491817266f2d62f5914212d8783ee67 | |
parent | 5329726352f8b983e419b6206a85c15cc8836676 (diff) | |
download | otp-9110ba256099e6fa55461fc4ca90da5ec4b2966b.tar.gz otp-9110ba256099e6fa55461fc4ca90da5ec4b2966b.tar.bz2 otp-9110ba256099e6fa55461fc4ca90da5ec4b2966b.zip |
[socket-nif] Add support for socket (level socket) option oobinline
Added support for socket level socket option oobinline (both get
and set).
OTP-14831
-rw-r--r-- | erts/emulator/nifs/common/socket_nif.c | 67 | ||||
-rw-r--r-- | erts/preloaded/ebin/socket.beam | bin | 43668 -> 43748 bytes | |||
-rw-r--r-- | erts/preloaded/src/socket.erl | 34 | ||||
-rw-r--r-- | lib/kernel/test/socket_server.erl | 10 |
4 files changed, 84 insertions, 27 deletions
diff --git a/erts/emulator/nifs/common/socket_nif.c b/erts/emulator/nifs/common/socket_nif.c index 4cc953df62..82468c6e8f 100644 --- a/erts/emulator/nifs/common/socket_nif.c +++ b/erts/emulator/nifs/common/socket_nif.c @@ -353,13 +353,14 @@ typedef union { #define SOCKET_OPT_SOCK_DONTROUTE 8 #define SOCKET_OPT_SOCK_KEEPALIVE 10 #define SOCKET_OPT_SOCK_LINGER 11 -#define SOCKET_OPT_SOCK_PEEK_OFF 16 -#define SOCKET_OPT_SOCK_PRIORITY 18 -#define SOCKET_OPT_SOCK_PROTOCOL 19 -#define SOCKET_OPT_SOCK_RCVBUF 20 -#define SOCKET_OPT_SOCK_REUSEADDR 24 -#define SOCKET_OPT_SOCK_SNDBUF 30 -#define SOCKET_OPT_SOCK_TYPE 35 +#define SOCKET_OPT_SOCK_OOBINLINE 13 +#define SOCKET_OPT_SOCK_PEEK_OFF 15 +#define SOCKET_OPT_SOCK_PRIORITY 17 +#define SOCKET_OPT_SOCK_PROTOCOL 18 +#define SOCKET_OPT_SOCK_RCVBUF 19 +#define SOCKET_OPT_SOCK_REUSEADDR 23 +#define SOCKET_OPT_SOCK_SNDBUF 27 +#define SOCKET_OPT_SOCK_TYPE 32 #define SOCKET_OPT_IP_RECVTOS 25 #define SOCKET_OPT_IP_ROUTER_ALERT 28 @@ -808,6 +809,11 @@ static ERL_NIF_TERM nsetopt_lvl_sock_linger(ErlNifEnv* env, SocketDescriptor* descP, ERL_NIF_TERM eVal); #endif +#if defined(SO_OOBINLINE) +static ERL_NIF_TERM nsetopt_lvl_sock_oobinline(ErlNifEnv* env, + SocketDescriptor* descP, + ERL_NIF_TERM eVal); +#endif #if defined(SO_PEEK_OFF) static ERL_NIF_TERM nsetopt_lvl_sock_peek_off(ErlNifEnv* env, SocketDescriptor* descP, @@ -970,6 +976,10 @@ static ERL_NIF_TERM ngetopt_lvl_sock_keepalive(ErlNifEnv* env, static ERL_NIF_TERM ngetopt_lvl_sock_linger(ErlNifEnv* env, SocketDescriptor* descP); #endif +#if defined(SO_OOBINLINE) +static ERL_NIF_TERM ngetopt_lvl_sock_oobinline(ErlNifEnv* env, + SocketDescriptor* descP); +#endif #if defined(SO_PEEK_OFF) static ERL_NIF_TERM ngetopt_lvl_sock_peek_off(ErlNifEnv* env, SocketDescriptor* descP); @@ -3739,6 +3749,12 @@ ERL_NIF_TERM nsetopt_lvl_socket(ErlNifEnv* env, break; #endif +#if defined(SO_OOBINLINE) + case SOCKET_OPT_SOCK_OOBINLINE: + result = nsetopt_lvl_sock_oobinline(env, descP, eVal); + break; +#endif + #if defined(SO_PRIORITY) case SOCKET_OPT_SOCK_PRIORITY: result = nsetopt_lvl_sock_priority(env, descP, eVal); @@ -3842,13 +3858,13 @@ ERL_NIF_TERM nsetopt_lvl_sock_linger(ErlNifEnv* env, #endif -#if defined(SO_PRIORITY) +#if defined(SO_OOBINLINE) static -ERL_NIF_TERM nsetopt_lvl_sock_priority(ErlNifEnv* env, - SocketDescriptor* descP, - ERL_NIF_TERM eVal) +ERL_NIF_TERM nsetopt_lvl_sock_oobinline(ErlNifEnv* env, + SocketDescriptor* descP, + ERL_NIF_TERM eVal) { - return nsetopt_int_opt(env, descP, SOL_SOCKET, SO_PRIORITY, eVal); + return nsetopt_bool_opt(env, descP, SOL_SOCKET, SO_OOBINLINE, eVal); } #endif @@ -3864,6 +3880,17 @@ ERL_NIF_TERM nsetopt_lvl_sock_peek_off(ErlNifEnv* env, #endif +#if defined(SO_PRIORITY) +static +ERL_NIF_TERM nsetopt_lvl_sock_priority(ErlNifEnv* env, + SocketDescriptor* descP, + ERL_NIF_TERM eVal) +{ + return nsetopt_int_opt(env, descP, SOL_SOCKET, SO_PRIORITY, eVal); +} +#endif + + #if defined(SO_RCVBUF) static ERL_NIF_TERM nsetopt_lvl_sock_rcvbuf(ErlNifEnv* env, @@ -4825,6 +4852,12 @@ ERL_NIF_TERM ngetopt_lvl_socket(ErlNifEnv* env, break; #endif +#if defined(SO_OOBINLINE) + case SOCKET_OPT_SOCK_OOBINLINE: + result = ngetopt_lvl_sock_oobinline(env, descP); + break; +#endif + #if defined(SO_PEEK_OFF) case SOCKET_OPT_SOCK_PEEK_OFF: result = ngetopt_lvl_sock_peek_off(env, descP); @@ -5001,6 +5034,16 @@ ERL_NIF_TERM ngetopt_lvl_sock_linger(ErlNifEnv* env, #endif +#if defined(SO_OOBINLINE) +static +ERL_NIF_TERM ngetopt_lvl_sock_oobinline(ErlNifEnv* env, + SocketDescriptor* descP) +{ + return ngetopt_bool_opt(env, descP, SOL_SOCKET, SO_OOBINLINE); +} +#endif + + #if defined(SO_PEEK_OFF) static ERL_NIF_TERM ngetopt_lvl_sock_peek_off(ErlNifEnv* env, diff --git a/erts/preloaded/ebin/socket.beam b/erts/preloaded/ebin/socket.beam Binary files differindex 9c10182bb4..4e8c848539 100644 --- a/erts/preloaded/ebin/socket.beam +++ b/erts/preloaded/ebin/socket.beam diff --git a/erts/preloaded/src/socket.erl b/erts/preloaded/src/socket.erl index 8f489bd681..278a3f17ad 100644 --- a/erts/preloaded/src/socket.erl +++ b/erts/preloaded/src/socket.erl @@ -476,16 +476,26 @@ -define(SOCKET_OPT_SOCK_KEEPALIVE, 10). -define(SOCKET_OPT_SOCK_LINGER, 11). %% -define(SOCKET_OPT_SOCK_MARK, 12). -%% -define(SOCKET_OPT_SOCK_OOBINLLINE, 13). +-define(SOCKET_OPT_SOCK_OOBINLINE, 13). %% -define(SOCKET_OPT_SOCK_PASSCRED, 14). --define(SOCKET_OPT_SOCK_PEEK_OFF, 16). -%% -define(SOCKET_OPT_SOCK_PEEKCRED, 17). --define(SOCKET_OPT_SOCK_PRIORITY, 18). --define(SOCKET_OPT_SOCK_PROTOCOL, 19). --define(SOCKET_OPT_SOCK_RCVBUF, 20). --define(SOCKET_OPT_SOCK_REUSEADDR, 24). --define(SOCKET_OPT_SOCK_SNDBUF, 30). --define(SOCKET_OPT_SOCK_TYPE, 35). +-define(SOCKET_OPT_SOCK_PEEK_OFF, 15). +%% -define(SOCKET_OPT_SOCK_PEEKCRED, 16). +-define(SOCKET_OPT_SOCK_PRIORITY, 17). +-define(SOCKET_OPT_SOCK_PROTOCOL, 18). +-define(SOCKET_OPT_SOCK_RCVBUF, 19). +%% -define(SOCKET_OPT_SOCK_RCVBUFFORCE, 20). +%% -define(SOCKET_OPT_SOCK_RCVLOWAT, 21). +%% -define(SOCKET_OPT_SOCK_RCVTIMEO, 22). +-define(SOCKET_OPT_SOCK_REUSEADDR, 23). +%% -define(SOCKET_OPT_SOCK_REUSEPORT, 24). +%% -define(SOCKET_OPT_SOCK_RXQ_OVFL, 25). +%% -define(SOCKET_OPT_SOCK_SETFIB, 26). +-define(SOCKET_OPT_SOCK_SNDBUF, 27). +%% -define(SOCKET_OPT_SOCK_SNDBUFFORCE, 28). +%% -define(SOCKET_OPT_SOCK_SNDLOWAT, 29). +%% -define(SOCKET_OPT_SOCK_SNDTIMEO, 30). +%% -define(SOCKET_OPT_SOCK_TIMESTAMP, 31). +-define(SOCKET_OPT_SOCK_TYPE, 32). -define(SOCKET_OPT_IP_RECVTOS, 25). -define(SOCKET_OPT_IP_ROUTER_ALERT, 28). @@ -1840,6 +1850,8 @@ enc_setopt_value(socket, linger, abort, D, T, P) -> enc_setopt_value(socket, linger, {OnOff, Secs} = V, _D, _T, _P) when is_boolean(OnOff) andalso is_integer(Secs) andalso (Secs >= 0) -> V; +enc_setopt_value(socket, oobinline, V, _D, _T, _P) when is_boolean(V) -> + V; enc_setopt_value(socket, peek_off, V, _D, _T, _P) when is_integer(V) -> V; enc_setopt_value(socket, priority, V, _D, _T, _P) when is_integer(V) -> @@ -2066,8 +2078,8 @@ enc_sockopt_key(socket, linger = _Opt, _Dir, _D, _T, _P) -> ?SOCKET_OPT_SOCK_LINGER; enc_sockopt_key(socket = L, mark = Opt, _Dir, _D, _T, _P) -> not_supported({L, Opt}); -enc_sockopt_key(socket, oobinline = Opt, _Dir, _D, _T, _P) -> - not_supported(Opt); +enc_sockopt_key(socket = _L, oobinline = _Opt, _Dir, _D, _T, _P) -> + ?SOCKET_OPT_SOCK_OOBINLINE; enc_sockopt_key(socket = L, passcred = Opt, _Dir, _D, _T, _P) -> not_supported({L, Opt}); enc_sockopt_key(socket = _L, peek_off = _Opt, _Dir, local = _D, _T, _P) -> diff --git a/lib/kernel/test/socket_server.erl b/lib/kernel/test/socket_server.erl index e5338644b1..da5a2ca905 100644 --- a/lib/kernel/test/socket_server.erl +++ b/lib/kernel/test/socket_server.erl @@ -438,11 +438,13 @@ handler_init(Manager, ID, Peek, Sock) -> {ok, Domain} = socket:getopt(Sock, socket, domain), {ok, Type} = socket:getopt(Sock, socket, type), {ok, Proto} = socket:getopt(Sock, socket, protocol), + {ok, OOBI} = socket:getopt(Sock, socket, oobinline), i("got continue when: " - "~n Domain: ~p" - "~n Type: ~p" - "~n Protocol: ~p", [Domain, Type, Proto]), - %% socket:setopt(Socket, otp, debug, true), + "~n Domain: ~p" + "~n Type: ~p" + "~n Protocol: ~p" + "~n OOBInline: ~p", [Domain, Type, Proto, OOBI]), + %% socket:setopt(Sock, otp, debug, true), handler_loop(#handler{peek = Peek, manager = Manager, type = Type, |