From 6e2af00879977b12f9fcf2f4570b4fe69f3c7b8f Mon Sep 17 00:00:00 2001 From: William Yang Date: Thu, 21 Mar 2024 20:24:08 +0100 Subject: [PATCH] feat: ioctl outq --- erts/emulator/nifs/common/prim_socket_nif.c | 5 +++++ erts/emulator/nifs/unix/unix_socket_syncio.c | 23 ++++++++++++++++++++ lib/kernel/doc/src/socket.xml | 1 + lib/kernel/src/socket.erl | 5 +++-- 4 files changed, 32 insertions(+), 2 deletions(-) diff --git a/erts/emulator/nifs/common/prim_socket_nif.c b/erts/emulator/nifs/common/prim_socket_nif.c index b80f7bea5f6f..003aba05e9b5 100644 --- a/erts/emulator/nifs/common/prim_socket_nif.c +++ b/erts/emulator/nifs/common/prim_socket_nif.c @@ -2405,6 +2405,7 @@ ERL_NIF_TERM esock_atom_socket_tag; // This has a "special" name ('$socket') LOCAL_ATOM_DECL(nread); \ LOCAL_ATOM_DECL(nspace); \ LOCAL_ATOM_DECL(nwrite); \ + LOCAL_ATOM_DECL(outq); \ LOCAL_ATOM_DECL(null); \ LOCAL_ATOM_DECL(num_acceptors); \ LOCAL_ATOM_DECL(num_cnt_bits); \ @@ -4881,6 +4882,10 @@ ERL_NIF_TERM esock_supports_ioctl_requests(ErlNifEnv* env) requests = MKC(env, MKT2(env, atom_nspace, MKUL(env, FIONSPACE)), requests); #endif +#if defined(TIOCOUTQ) + requests = MKC(env, MKT2(env, atom_outq, MKUL(env, TIOCOUTQ)), requests); +#endif + #if defined(SIOCATMARK) requests = MKC(env, MKT2(env, atom_atmark, MKUL(env, SIOCATMARK)), requests); #endif diff --git a/erts/emulator/nifs/unix/unix_socket_syncio.c b/erts/emulator/nifs/unix/unix_socket_syncio.c index a2a92c02ad1a..00bc46ebf54b 100644 --- a/erts/emulator/nifs/unix/unix_socket_syncio.c +++ b/erts/emulator/nifs/unix/unix_socket_syncio.c @@ -450,6 +450,13 @@ static ERL_NIF_TERM essio_ioctl_gifconf(ErlNifEnv* env, #define IOCTL_FIONSPACE_FUNC2_DEF #endif +/* esock_ioctl_tiocoutq */ +#if defined(TIOCOUTQ) +#define IOCTL_TIOCOUTQ_FUNC2_DEF IOCTL_GET_FUNC2_DEF(siocoutq) +#else +#define IOCTL_TIOCOUTQ_FUNC2_DEF +#endif + /* esock_ioctl_siocatmark */ #if defined(SIOCATMARK) #define IOCTL_SIOCATMARK_FUNC2_DEF IOCTL_GET_FUNC2_DEF(siocatmark) @@ -461,6 +468,7 @@ static ERL_NIF_TERM essio_ioctl_gifconf(ErlNifEnv* env, IOCTL_FIONREAD_FUNC2_DEF; \ IOCTL_FIONWRITE_FUNC2_DEF; \ IOCTL_FIONSPACE_FUNC2_DEF; \ + IOCTL_TIOCOUTQ_FUNC2_DEF; \ IOCTL_SIOCATMARK_FUNC2_DEF; #define IOCTL_GET_FUNC2_DEF(F) \ static ERL_NIF_TERM essio_ioctl_##F(ErlNifEnv* env, \ @@ -3865,6 +3873,12 @@ ERL_NIF_TERM essio_ioctl2(ErlNifEnv* env, break; #endif +#if defined(TIOCOUTQ) + case TIOCOUTQ: + return essio_ioctl_siocoutq(env, descP); + break; +#endif + #if defined(SIOCATMARK) case SIOCATMARK: return essio_ioctl_siocatmark(env, descP); @@ -4193,10 +4207,19 @@ ERL_NIF_TERM essio_ioctl_gifconf(ErlNifEnv* env, #define IOCTL_FIONSPACE_FUNC2_DECL #endif +/* *** essio_ioctl_siocoutq *** */ +#if defined(TIOCOUTQ) +#define IOCTL_TIOCOUTQ_FUNC2_DECL \ + IOCTL_GET_REQUEST2_DECL(siocoutq, TIOCOUTQ, ivalue) +#else +#define IOCTL_TIOCOUTQ_FUNC2_DECL +#endif + #define IOCTL_GET_FUNCS2 \ IOCTL_FIONREAD_FUNC2_DECL \ IOCTL_FIONWRITE_FUNC2_DECL \ IOCTL_FIONSPACE_FUNC2_DECL \ + IOCTL_TIOCOUTQ_FUNC2_DECL \ IOCTL_SIOCATMARK_FUNC2_DECL #define IOCTL_GET_REQUEST2_DECL(OR, R, EF) \ diff --git a/lib/kernel/doc/src/socket.xml b/lib/kernel/doc/src/socket.xml index 6dc84a2adb72..70ed048c94b9 100644 --- a/lib/kernel/doc/src/socket.xml +++ b/lib/kernel/doc/src/socket.xml @@ -2246,6 +2246,7 @@ nwrite + @TODO outq

The number of bytes in the send queue.

Result, number of bytes, is a integer().

diff --git a/lib/kernel/src/socket.erl b/lib/kernel/src/socket.erl index 68e79e599c34..b37bfbb8351b 100644 --- a/lib/kernel/src/socket.erl +++ b/lib/kernel/src/socket.erl @@ -4443,7 +4443,7 @@ peername(Socket) -> Socket :: socket(), Reason :: posix() | 'closed'; - (Socket, GetRequest :: 'nread' | 'nwrite' | 'nspace') -> + (Socket, GetRequest :: 'nread' | 'nwrite' | 'outq' | 'nspace') -> {'ok', NumBytes :: non_neg_integer()} | {'error', Reason} when Socket :: socket(), Reason :: posix() | 'closed'; @@ -4458,12 +4458,13 @@ peername(Socket) -> Socket :: socket(), Reason :: posix() | 'closed'. -%% gifconf | nread | nwrite | nspace | atmark | +%% gifconf | nread | nwrite | nspace | outq | atmark | %% {gifaddr, string()} | {gifindex, string()} | {gifname, integer()} ioctl(?socket(SockRef), gifconf = GetRequest) -> prim_socket:ioctl(SockRef, GetRequest); ioctl(?socket(SockRef), GetRequest) when (nread =:= GetRequest) orelse (nwrite =:= GetRequest) orelse + (outq =:= GetRequest) orelse (nspace =:= GetRequest) -> prim_socket:ioctl(SockRef, GetRequest); ioctl(?socket(SockRef), GetRequest) when (atmark =:= GetRequest) ->