Skip to content
Snippets Groups Projects
Commit 86c4544e authored by Paul Sokolovsky's avatar Paul Sokolovsky
Browse files

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.
parent 69f0b4ad
No related branches found
No related tags found
No related merge requests found
...@@ -153,6 +153,7 @@ static void sock_received_cb(struct net_context *context, struct net_pkt *pkt, i ...@@ -153,6 +153,7 @@ static void sock_received_cb(struct net_context *context, struct net_pkt *pkt, i
struct net_pkt *last_pkt = _k_fifo_peek_tail(&socket->recv_q); struct net_pkt *last_pkt = _k_fifo_peek_tail(&socket->recv_q);
if (last_pkt == NULL) { if (last_pkt == NULL) {
socket->state = STATE_PEER_CLOSED; socket->state = STATE_PEER_CLOSED;
k_fifo_cancel_wait(&socket->recv_q);
DEBUG_printf("Marked socket %p as peer-closed\n", socket); DEBUG_printf("Marked socket %p as peer-closed\n", socket);
} else { } else {
// We abuse "buf_sent" flag to store EOF flag // 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 * ...@@ -378,6 +379,11 @@ STATIC mp_uint_t sock_read(mp_obj_t self_in, void *buf, mp_uint_t max_len, int *
DEBUG_printf("TCP recv: no cur_pkt, getting\n"); DEBUG_printf("TCP recv: no cur_pkt, getting\n");
struct net_pkt *pkt = k_fifo_get(&socket->recv_q, K_FOREVER); struct net_pkt *pkt = k_fifo_get(&socket->recv_q, K_FOREVER);
if (pkt == NULL) {
DEBUG_printf("TCP recv: NULL return from fifo\n");
continue;
}
DEBUG_printf("TCP recv: new cur_pkt: %p\n", pkt); DEBUG_printf("TCP recv: new cur_pkt: %p\n", pkt);
socket->cur_pkt = pkt; socket->cur_pkt = pkt;
} }
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment