zephyr/modusocket: sock_read: Check socket status only at the start of packet.

Otherwise, if we already have a packet in progress, finish it first, before
check "peer closed" status.
This commit is contained in:
Paul Sokolovsky 2017-04-26 09:06:58 +03:00
parent 1fe0f678f8
commit 868453d3d8
1 changed files with 4 additions and 3 deletions

View File

@ -373,11 +373,12 @@ STATIC mp_uint_t sock_read(mp_obj_t self_in, void *buf, mp_uint_t max_len, int *
} else if (sock_type == SOCK_STREAM) { } else if (sock_type == SOCK_STREAM) {
do { do {
if (socket->cur_buf == NULL) {
if (socket->state == STATE_PEER_CLOSED) { if (socket->state == STATE_PEER_CLOSED) {
return 0; return 0;
} }
if (socket->cur_buf == NULL) {
DEBUG_printf("TCP recv: no cur_buf, getting\n"); DEBUG_printf("TCP recv: no cur_buf, getting\n");
struct net_buf *net_buf = k_fifo_get(&socket->recv_q, K_FOREVER); struct net_buf *net_buf = k_fifo_get(&socket->recv_q, K_FOREVER);
// Restore ->frags overwritten by fifo // Restore ->frags overwritten by fifo