Skip to content

Commit 20a51b4

Browse files
jukkarnashif
authored andcommitted
net: sockets: Release the socket lock if needed
If we are waiting all the data i.e., the MSG_WAITALL flag is set, then if we have not yet received all the data at the end of the receive loop. We must use the condition variable to get the signal when the data is ready to be received. Otherwise the receive loop will not release the socket lock and receive_cb will not be able to indicate that data is received. Signed-off-by: Jukka Rissanen <[email protected]>
1 parent 1184089 commit 20a51b4

File tree

1 file changed

+6
-11
lines changed

1 file changed

+6
-11
lines changed

subsys/net/lib/sockets/sockets.c

Lines changed: 6 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1129,12 +1129,6 @@ static inline ssize_t zsock_recv_stream(struct net_context *ctx,
11291129
timeout = K_NO_WAIT;
11301130
} else if (!sock_is_eof(ctx)) {
11311131
net_context_get_option(ctx, NET_OPT_RCVTIMEO, &timeout, NULL);
1132-
1133-
res = wait_data(ctx, &timeout);
1134-
if (res < 0) {
1135-
errno = -res;
1136-
return -1;
1137-
}
11381132
}
11391133

11401134
end = sys_clock_timeout_end_calc(timeout);
@@ -1148,11 +1142,12 @@ static inline ssize_t zsock_recv_stream(struct net_context *ctx,
11481142
return 0;
11491143
}
11501144

1151-
res = k_fifo_wait_non_empty(&ctx->recv_q, timeout);
1152-
/* EAGAIN when timeout expired, EINTR when cancelled */
1153-
if (res && res != -EAGAIN && res != -EINTR) {
1154-
errno = -res;
1155-
return -1;
1145+
if (!K_TIMEOUT_EQ(timeout, K_NO_WAIT)) {
1146+
res = wait_data(ctx, &timeout);
1147+
if (res < 0) {
1148+
errno = -res;
1149+
return -1;
1150+
}
11561151
}
11571152

11581153
pkt = k_fifo_peek_head(&ctx->recv_q);

0 commit comments

Comments
 (0)