Skip to content

Commit

Permalink
Fix CI failure
Browse files Browse the repository at this point in the history
Signed-off-by: Fred Dushin <fred@dushin.net>
  • Loading branch information
fadushin committed Nov 10, 2023
1 parent 777757a commit 9cc21e1
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 6 deletions.
2 changes: 1 addition & 1 deletion src/libAtomVM/otp_socket.c
Original file line number Diff line number Diff line change
Expand Up @@ -1765,7 +1765,7 @@ static term nif_socket_recv_without_peek(Context *ctx, struct SocketResource *rs
GlobalContext *global = ctx->global;

size_t buffer_size = len == 0 ? rsrc_obj->buf_size : len;
char *buffer = malloc(buffer_size);
uint8_t *buffer = (uint8_t *) malloc(buffer_size);
term payload = term_invalid_term();

if (IS_NULL_PTR(buffer)) {
Expand Down
26 changes: 21 additions & 5 deletions tests/libs/estdlib/test_tcp_socket.erl
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ test() ->
ok = test_shutdown(),
ok = test_close_by_another_process(),
ok = test_buf_size(),
ok = test_override_buf_size(),
case get_otp_version() of
atomvm ->
ok = test_abandon_select();
Expand Down Expand Up @@ -135,16 +136,31 @@ test_buf_size() ->

%% we should only be able to receive
ok = check_receive(Socket, Packet, 0, <<"0123456789">>),
ok = check_receive(Socket, Packet, 0, <<"0123456789">>),
ok = check_receive(Socket, Packet, 0, <<"0123456789">>),

ok = close_client_socket(Socket),

close_listen_socket(ListenSocket).

test_override_buf_size() ->
etest:flush_msg_queue(),

Port = 44404,
ListenSocket = start_echo_server(Port),

{ok, Socket} = socket:open(inet, stream, tcp),
ok = try_connect(Socket, Port, 10),

%% limit the recv buffer size to 10 bytes
ok = socket:setopt(Socket, {otp, rcvbuf}, 10),

%% read the remaining 20 bytes
_ = socket:recv(Socket, 20),
Packet = "012345678901234567890123456789",

%% verify that the socket:recv length parameter takes
%% precedence over the default
ok = check_receive(Socket, Packet, 15, <<"012345678901234">>),

%% read the remaining 15 bytes
_ = socket:recv(Socket, 20),
ok = check_receive(Socket, Packet, 15, <<"012345678901234">>),

ok = close_client_socket(Socket),

Expand Down

0 comments on commit 9cc21e1

Please sign in to comment.