Skip to content

Commit 96166ec

Browse files
committed
zephyr/modusocket: socket_bind: Don't set recv callback on STREAM sockets.
For stream sockets, next exected operation is listen().
1 parent f1c0676 commit 96166ec

1 file changed

Lines changed: 7 additions & 2 deletions

File tree

zephyr/modusocket.c

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -224,8 +224,13 @@ STATIC mp_obj_t socket_bind(mp_obj_t self_in, mp_obj_t addr_in) {
224224
parse_inet_addr(socket, addr_in, &sockaddr);
225225

226226
RAISE_ERRNO(net_context_bind(socket->ctx, &sockaddr, sizeof(sockaddr)));
227-
DEBUG_printf("Setting recv cb after bind\n");
228-
RAISE_ERRNO(net_context_recv(socket->ctx, sock_received_cb, K_NO_WAIT, socket));
227+
// For DGRAM socket, we expect to receive packets after call to bind(),
228+
// but for STREAM socket, next expected operation is listen(), which
229+
// doesn't work if recv callback is set.
230+
if (net_context_get_type(socket->ctx) == SOCK_DGRAM) {
231+
DEBUG_printf("Setting recv cb after bind\n");
232+
RAISE_ERRNO(net_context_recv(socket->ctx, sock_received_cb, K_NO_WAIT, socket));
233+
}
229234
return mp_const_none;
230235
}
231236
STATIC MP_DEFINE_CONST_FUN_OBJ_2(socket_bind_obj, socket_bind);

0 commit comments

Comments
 (0)