Skip to content

Commit dbeda5b

Browse files
committed
Merge pull request atomvm#589 from pguyot/w21/fix-gen_udp-packet-format
Fix format of gen_udp active packet on esp32 (fix atomvm#589) These changes are made under both the "Apache 2.0" and the "GNU Lesser General Public License 2.1 or later" license terms (dual license). SPDX-License-Identifier: Apache-2.0 OR LGPL-2.1-or-later
2 parents c6bf045 + c4a9310 commit dbeda5b

File tree

2 files changed

+11
-5
lines changed

2 files changed

+11
-5
lines changed

src/platforms/esp32/components/avm_builtins/socket_driver.c

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -688,10 +688,16 @@ static NativeHandlerResult do_receive_data(Context *ctx)
688688

689689

690690
if (socket_data->active) {
691-
term active_tuple = term_alloc_tuple(3, &ctx->heap);
691+
term active_tuple = term_alloc_tuple(socket_data->type == TCPClientSocket ? 3 : 5, &ctx->heap);
692692
term_put_tuple_element(active_tuple, 0, socket_data->type == TCPClientSocket ? TCP_ATOM : UDP_ATOM);
693693
term_put_tuple_element(active_tuple, 1, term_from_local_process_id(ctx->process_id));
694-
term_put_tuple_element(active_tuple, 2, recv_term);
694+
if (socket_data->type == TCPClientSocket) {
695+
term_put_tuple_element(active_tuple, 2, recv_term);
696+
} else {
697+
term_put_tuple_element(active_tuple, 2, term_get_tuple_element(recv_term, 0));
698+
term_put_tuple_element(active_tuple, 3, term_get_tuple_element(recv_term, 1));
699+
term_put_tuple_element(active_tuple, 4, recv_data);
700+
}
695701
globalcontext_send_message(ctx->global, socket_data->controlling_process_pid, active_tuple);
696702
TRACE("sent received to active process (pid=%d): ", socket_data->controlling_process_pid);
697703
#ifdef ENABLE_TRACE

src/platforms/esp32/test/main/test_erl_sources/test_socket.erl

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -155,12 +155,12 @@ test_udp(Active, QueryID) ->
155155
ok =
156156
receive
157157
% {udp, Socket, {{1,1,1,1}, 53, <<QueryID:16, 1:1, _:7, _/binary>>}} -> ok; % not supported yet
158-
{udp, Socket, {{1, 1, 1, 1}, 53, <<QueryID:16, B, _/binary>>}} when
158+
{udp, Socket, {1, 1, 1, 1}, 53, <<QueryID:16, B, _/binary>>} when
159159
B band 16#80 =:= 16#80
160160
->
161161
ok;
162-
{udp, Socket, Packet} ->
163-
{unexpected_packet, Packet};
162+
{udp, Socket, Addr, Port, Packet} ->
163+
{unexpected_packet, Addr, Port, Packet};
164164
UnexpectedAfterSend ->
165165
{unexpected_message_after_send, UnexpectedAfterSend}
166166
after 10000 ->

0 commit comments

Comments
 (0)