Skip to content

Commit

Permalink
feat: ioctl outq
Browse files Browse the repository at this point in the history
  • Loading branch information
qzhuyan committed Mar 21, 2024
1 parent 35dfc90 commit 6e2af00
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 2 deletions.
5 changes: 5 additions & 0 deletions erts/emulator/nifs/common/prim_socket_nif.c
Original file line number Diff line number Diff line change
Expand Up @@ -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); \
Expand Down Expand Up @@ -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
Expand Down
23 changes: 23 additions & 0 deletions erts/emulator/nifs/unix/unix_socket_syncio.c
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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, \
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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) \
Expand Down
1 change: 1 addition & 0 deletions lib/kernel/doc/src/socket.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2246,6 +2246,7 @@
</item>

<tag><c>nwrite</c></tag>
<tag><c>@TODO outq</c></tag>
<item>
<p>The number of bytes in the send queue. </p>
<p>Result, number of bytes, is a <c>integer()</c>. </p>
Expand Down
5 changes: 3 additions & 2 deletions lib/kernel/src/socket.erl
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand All @@ -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) ->
Expand Down

0 comments on commit 6e2af00

Please sign in to comment.