Skip to content

Commit 3a01736

Browse files
committed
feat: impl tcp unsend
fetch driver queue in binary caller will recv ``` {Port, {data, ["?unsend?" | Binary]}} ````
1 parent 928d03e commit 3a01736

File tree

4 files changed

+34
-0
lines changed

4 files changed

+34
-0
lines changed

erts/emulator/drivers/common/inet_drv.c

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -816,6 +816,7 @@ static size_t my_strnlen(const char *s, size_t maxlen)
816816
#define TCP_REQ_UNRECV 43
817817
#define TCP_REQ_SHUTDOWN 44
818818
#define TCP_REQ_SENDFILE 45
819+
#define TCP_REQ_UNSEND 46
819820
/* UDP and SCTP requests */
820821
#define PACKET_REQ_RECV 60 /* Common for UDP and SCTP */
821822
/* #define SCTP_REQ_LISTEN 61 MERGED Different from TCP; not for UDP */
@@ -11904,6 +11905,25 @@ static ErlDrvSSizeT tcp_inet_ctl(ErlDrvData e, unsigned int cmd,
1190411905
return ctl_reply(INET_REP_OK, NULL, 0, rbuf, rsize);
1190511906
}
1190611907

11908+
case TCP_REQ_UNSEND: {
11909+
ErlIOVec iov;
11910+
ErlDrvSizeT sz;
11911+
11912+
DDBG(INETP(desc),
11913+
("INET-DRV-DBG[%d][" SOCKET_FSTR ",%T] tcp_inet_ctl -> UNSEND\r\n",
11914+
__LINE__, desc->inet.s, driver_caller(desc->inet.port)) );
11915+
if (!IS_CONNECTED(INETP(desc)))
11916+
return ctl_error(ENOTCONN, rbuf, rsize);
11917+
11918+
sz = driver_peekqv(desc->inet.port, &iov);
11919+
11920+
if (sz > 0)
11921+
{
11922+
driver_outputv(desc->inet.port, "?unsend?", sizeof("?unsend?"), &iov, 0);
11923+
}
11924+
11925+
return ctl_reply(sz?INET_REP_OK:INET_REP_ERROR, NULL, 0, rbuf, rsize);
11926+
}
1190711927

1190811928
case TCP_REQ_SHUTDOWN: {
1190911929
int how;

erts/preloaded/ebin/prim_inet.beam

68 Bytes
Binary file not shown.

erts/preloaded/src/prim_inet.erl

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@
3434
-export([send/2, send/3, sendto/4, sendmsg/3, sendfile/4]).
3535
-export([recv/2, recv/3, async_recv/3]).
3636
-export([unrecv/2]).
37+
-export([unsend/2]).
3738
-export([recvfrom/2, recvfrom/3]).
3839
-export([setopt/3, setopts/2, getopt/2, getopts/2, is_sockopt_val/2]).
3940
-export([chgopt/3, chgopts/2]).
@@ -1468,6 +1469,18 @@ unrecv(S, Data) ->
14681469

14691470
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
14701471
%%
1472+
%% UNSEND(insock(), data) -> ok | {error, Reason}
1473+
%%
1474+
%%
1475+
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1476+
1477+
unsend(S, Data) ->
1478+
case ctl_cmd(S, ?TCP_REQ_UNSEND, Data) of
1479+
{ok, _} -> ok;
1480+
{error,_}=Error -> Error
1481+
end.
1482+
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1483+
%%
14711484
%% DETACH(insock()) -> ok
14721485
%%
14731486
%% unlink from a socket

lib/kernel/src/inet_int.hrl

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,7 @@
102102
-define(TCP_REQ_UNRECV, 43).
103103
-define(TCP_REQ_SHUTDOWN, 44).
104104
-define(TCP_REQ_SENDFILE, 45).
105+
-define(TCP_REQ_UNSEND, 46).
105106

106107
%% UDP and SCTP requests
107108
-define(PACKET_REQ_RECV, 60).

0 commit comments

Comments
 (0)