Skip to content

fix: check recvsize before nonblocking mode in TCP recv() (AUD-004) - #183

Open
occamsshavingkit wants to merge 1 commit into
Wiznet:masterfrom
occamsshavingkit:fix/aud-004-nonblocking-tcp-recv-order
Open

fix: check recvsize before nonblocking mode in TCP recv() (AUD-004)#183
occamsshavingkit wants to merge 1 commit into
Wiznet:masterfrom
occamsshavingkit:fix/aud-004-nonblocking-tcp-recv-order

Conversation

@occamsshavingkit

Copy link
Copy Markdown

Summary

Fixes nonblocking TCP socket returning SOCK_BUSY even when RX data is available.

Problem

In the non-IPv6 W5500 path at Ethernet/socket.c:687-692, the #else branch checked nonblocking mode before checking recvsize != 0:

#else
    if (sock_io_mode & (1 << sn)) {   // checked first
        return SOCK_BUSY;
    }
    if (recvsize != 0) {              // checked second — too late
        break;
    }
#endif

A nonblocking TCP socket returned SOCK_BUSY even when RX data was available. The RX pointer never advanced, so retries could not drain the socket and the receive buffer eventually stalled.

Fix

Swap the two checks so recvsize != 0 is evaluated first, matching the ordering already used by the IPv6 branch at lines 679-685:

#else
    if (recvsize != 0) {              // checked first
        break;
    }
    if (sock_io_mode & (1 << sn)) {   // checked second
        return SOCK_BUSY;
    }
#endif

Verification

  • Multi-chip compile check: passes for all 7 _WIZCHIP_ values
  • An empty nonblocking socket still returns SOCK_BUSY (the check is still present, just reordered)

In the non-IPv6 W5500 path, socket.c:687-692 checked nonblocking mode
before checking recvsize != 0. A nonblocking TCP socket returned
SOCK_BUSY even when RX data was available, so the RX pointer never
advanced and retries could not drain the socket.

Fix: swap the two checks so recvsize != 0 is evaluated first, matching
the ordering already used by the IPv6 branch at lines 679-685.
niansa added a commit to niansa/ioLibrary_Driver that referenced this pull request Jul 29, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant