diff options
-rw-r--r-- | erts/emulator/nifs/common/socket_nif.c | 43 | ||||
-rw-r--r-- | erts/preloaded/ebin/socket.beam | bin | 43652 -> 43668 bytes | |||
-rw-r--r-- | erts/preloaded/src/socket.erl | 8 | ||||
-rw-r--r-- | lib/kernel/test/socket_server.erl | 37 |
4 files changed, 80 insertions, 8 deletions
diff --git a/erts/emulator/nifs/common/socket_nif.c b/erts/emulator/nifs/common/socket_nif.c index c2a8170227..4cc953df62 100644 --- a/erts/emulator/nifs/common/socket_nif.c +++ b/erts/emulator/nifs/common/socket_nif.c @@ -353,6 +353,7 @@ 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 @@ -807,6 +808,11 @@ static ERL_NIF_TERM nsetopt_lvl_sock_linger(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, + ERL_NIF_TERM eVal); +#endif #if defined(SO_PRIORITY) static ERL_NIF_TERM nsetopt_lvl_sock_priority(ErlNifEnv* env, SocketDescriptor* descP, @@ -964,6 +970,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_PEEK_OFF) +static ERL_NIF_TERM ngetopt_lvl_sock_peek_off(ErlNifEnv* env, + SocketDescriptor* descP); +#endif #if defined(SO_PRIORITY) static ERL_NIF_TERM ngetopt_lvl_sock_priority(ErlNifEnv* env, SocketDescriptor* descP); @@ -3723,6 +3733,12 @@ ERL_NIF_TERM nsetopt_lvl_socket(ErlNifEnv* env, break; #endif +#if defined(SO_PEEK_OFF) + case SOCKET_OPT_SOCK_PEEK_OFF: + result = nsetopt_lvl_sock_peek_off(env, descP, eVal); + break; +#endif + #if defined(SO_PRIORITY) case SOCKET_OPT_SOCK_PRIORITY: result = nsetopt_lvl_sock_priority(env, descP, eVal); @@ -3837,6 +3853,17 @@ ERL_NIF_TERM nsetopt_lvl_sock_priority(ErlNifEnv* env, #endif +#if defined(SO_PEEK_OFF) +static +ERL_NIF_TERM nsetopt_lvl_sock_peek_off(ErlNifEnv* env, + SocketDescriptor* descP, + ERL_NIF_TERM eVal) +{ + return nsetopt_int_opt(env, descP, SOL_SOCKET, SO_PEEK_OFF, eVal); +} +#endif + + #if defined(SO_RCVBUF) static ERL_NIF_TERM nsetopt_lvl_sock_rcvbuf(ErlNifEnv* env, @@ -4798,6 +4825,12 @@ ERL_NIF_TERM ngetopt_lvl_socket(ErlNifEnv* env, break; #endif +#if defined(SO_PEEK_OFF) + case SOCKET_OPT_SOCK_PEEK_OFF: + result = ngetopt_lvl_sock_peek_off(env, descP); + break; +#endif + #if defined(SO_PRIORITY) case SOCKET_OPT_SOCK_PRIORITY: result = ngetopt_lvl_sock_priority(env, descP); @@ -4968,6 +5001,16 @@ ERL_NIF_TERM ngetopt_lvl_sock_linger(ErlNifEnv* env, #endif +#if defined(SO_PEEK_OFF) +static +ERL_NIF_TERM ngetopt_lvl_sock_peek_off(ErlNifEnv* env, + SocketDescriptor* descP) +{ + return ngetopt_int_opt(env, descP, SOL_SOCKET, SO_PEEK_OFF); +} +#endif + + #if defined(SO_PRIORITY) static ERL_NIF_TERM ngetopt_lvl_sock_priority(ErlNifEnv* env, diff --git a/erts/preloaded/ebin/socket.beam b/erts/preloaded/ebin/socket.beam Binary files differindex 508c669895..9c10182bb4 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 66ae9c7fd8..8f489bd681 100644 --- a/erts/preloaded/src/socket.erl +++ b/erts/preloaded/src/socket.erl @@ -478,7 +478,7 @@ %% -define(SOCKET_OPT_SOCK_MARK, 12). %% -define(SOCKET_OPT_SOCK_OOBINLLINE, 13). %% -define(SOCKET_OPT_SOCK_PASSCRED, 14). -%% -define(SOCKET_OPT_SOCK_PEEK_OFF, 16). +-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). @@ -1840,6 +1840,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, peek_off, V, _D, _T, _P) when is_integer(V) -> + V; enc_setopt_value(socket, priority, V, _D, _T, _P) when is_integer(V) -> V; enc_setopt_value(socket, rcvbuf, V, _D, _T, _P) when is_integer(V) -> @@ -2068,8 +2070,8 @@ enc_sockopt_key(socket, oobinline = Opt, _Dir, _D, _T, _P) -> not_supported(Opt); 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) -> - not_supported({L, Opt}); +enc_sockopt_key(socket = _L, peek_off = _Opt, _Dir, local = _D, _T, _P) -> + ?SOCKET_OPT_SOCK_PEEK_OFF; enc_sockopt_key(socket = L, peekcred = Opt, get = _Dir, _D, _T, _P) -> not_supported({L, Opt}); enc_sockopt_key(socket, priority = _Opt, _Dir, _D, _T, _P) -> diff --git a/lib/kernel/test/socket_server.erl b/lib/kernel/test/socket_server.erl index 54e13cc92d..e5338644b1 100644 --- a/lib/kernel/test/socket_server.erl +++ b/lib/kernel/test/socket_server.erl @@ -99,6 +99,25 @@ manager_init(Domain, dgram = Type, Proto, Peek) -> i("try open socket"), case socket:open(Domain, Type, Proto) of {ok, Sock} -> + F = fun(X) -> case socket:getopt(Sock, socket, X) of + {ok, V} -> f("~p", [V]); + {error, _} -> "-" + end + end, + i("(socket) open (~s,~s,~s): " + "~n broadcast: ~s" + "~n dontroute: ~s" + "~n keepalive: ~s" + "~n reuseaddr: ~s" + "~n linger: ~s" + "~n debug: ~s" + "~n prio: ~s" + "~n rcvbuf: ~s" + "~n sndbuf: ~s" + "~n try find (local) address", + [F(domain), F(type), F(protocol), + F(broadcast), F(dontroute), F(keepalive), F(reuseaddr), F(linger), + F(debug), F(priority), F(rcvbuf), F(sndbuf)]), Addr = which_addr(Domain), SA = #{family => Domain, addr => Addr}, @@ -260,14 +279,22 @@ acceptor_do_init(Domain, Type, Proto) -> end, F = fun(X) -> case socket:getopt(Sock, socket, X) of {ok, V} -> f("~p", [V]); - {error, _} -> "-" + {error, R} -> f("error: ~p", [R]) end end, i("(socket) open (~s,~s,~s): " - "~n debug: ~s" - "~n prio: ~s" - "~n try find (local) address", - [F(domain), F(type), F(protocol), F(debug), F(priority)]), + "~n dontroute: ~s" + "~n keepalive: ~s" + "~n reuseaddr: ~s" + "~n linger: ~s" + "~n debug: ~s" + "~n prio: ~s" + "~n rcvbuf: ~s" + "~n sndbuf: ~s" + "~n => try find (local) address", + [F(domain), F(type), F(protocol), + F(dontroute), F(keepalive), F(reuseaddr), F(linger), + F(debug), F(priority), F(rcvbuf), F(sndbuf)]), Addr = which_addr(Domain), SA = #{family => Domain, addr => Addr}, |