Skip to content

Commit 86c4544

Browse files
committed
zephyr/modusocket: If there're no packets in recv_q, cancel waiter.
This solves a case when socker_read() has blocked on fifo, and then peer closed event arrives.
1 parent 69f0b4a commit 86c4544

File tree

1 file changed

+6
-0
lines changed

1 file changed

+6
-0
lines changed

zephyr/modusocket.c

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -153,6 +153,7 @@ static void sock_received_cb(struct net_context *context, struct net_pkt *pkt, i
153153
struct net_pkt *last_pkt = _k_fifo_peek_tail(&socket->recv_q);
154154
if (last_pkt == NULL) {
155155
socket->state = STATE_PEER_CLOSED;
156+
k_fifo_cancel_wait(&socket->recv_q);
156157
DEBUG_printf("Marked socket %p as peer-closed\n", socket);
157158
} else {
158159
// We abuse "buf_sent" flag to store EOF flag
@@ -378,6 +379,11 @@ STATIC mp_uint_t sock_read(mp_obj_t self_in, void *buf, mp_uint_t max_len, int *
378379
DEBUG_printf("TCP recv: no cur_pkt, getting\n");
379380
struct net_pkt *pkt = k_fifo_get(&socket->recv_q, K_FOREVER);
380381

382+
if (pkt == NULL) {
383+
DEBUG_printf("TCP recv: NULL return from fifo\n");
384+
continue;
385+
}
386+
381387
DEBUG_printf("TCP recv: new cur_pkt: %p\n", pkt);
382388
socket->cur_pkt = pkt;
383389
}

0 commit comments

Comments
 (0)