Conversation
Fixed bsd_socket events handling.
There was a problem hiding this comment.
Pull request overview
This PR improves TCP transmit FIFO handling and wraparound logic, adds error checking for BSD socket calls, and significantly extends unit test coverage for the TCP/IP stack implementation.
Changes:
- Modified FIFO space calculation to return contiguous space only when wrapped, preventing buffer overrun issues
- Added explicit contiguous space check in fifo_push to prevent wraparound writes
- Added error handling for fifo_push calls in wolfIP_sock_sendto for TCP, UDP, and ICMP protocols
- Fixed PKT_FLAG_SENT clearing in tcp_ack to allow retransmission of acknowledged packets
- Modified wolfIP_sock_accept to set addrlen even when addr is NULL (POSIX compliance)
- Changed pthread_mutex_lock to pthread_mutex_trylock with busy-wait in BSD socket wrapper
- Added 90+ new unit tests covering socket operations, FIFO edge cases, and timer heap operations
- Added test infrastructure for mocking random number generation
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 3 comments.
| File | Description |
|---|---|
| src/wolfip.c | Core FIFO handling improvements for wraparound safety, error handling for buffer operations, TCP ACK flag fixes |
| src/test/unit/unit.c | Extensive new test coverage for sockets, FIFOs, timers, and routing with 90+ new test cases |
| src/port/posix/bsd_socket.c | Modified mutex acquisition strategy in blocking call wrapper |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
- Restored blocking pthread_mutex (improved performance in TCP sender) - fifo_push now considers wrapping around if possible, when the packet is bigger than the offered contiguous space at the end of the buffer, while there could be space at the beginning before tail pointer if the fifo wraps around.
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
- Fix in-flight calculation, bound cwnd to RWND - Only perform congestion control increases when traffic is CWND-limited - Add missing window scaling options parsing & sending per RFC7323
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 4 out of 4 changed files in this pull request and generated 17 comments.
Comments suppressed due to low confidence (1)
src/wolfip.c:1876
- In the duplicate ACK path, the conditions on lines 1867-1870 check if
ack != t->sock.tcp.snd_unaandbytes_in_flight == 0, returning early if true. However, the duplicate ACK logic should only trigger whenack == snd_unaAND there are bytes in flight. The early returns are correct, but the logic that follows assumes a duplicate ACK scenario without verifying that this is actually a duplicate (i.e., that we've seen this ACK value before). The fast retransmit logic then unconditionally reduces ssthresh and cwnd, which could incorrectly trigger on the first ACK with a given value. Consider adding a duplicate ACK counter to ensure the fast retransmit only triggers after receiving three duplicate ACKs as per RFC 5681.
/* Duplicate ack (no advance in snd_una). */
if (ack != t->sock.tcp.snd_una)
return;
if (t->sock.tcp.bytes_in_flight == 0)
return;
t->sock.tcp.ssthresh = t->sock.tcp.cwnd / 2;
if (t->sock.tcp.ssthresh < 2 * TCP_MSS) {
t->sock.tcp.ssthresh = 2 * TCP_MSS;
}
t->sock.tcp.cwnd = t->sock.tcp.ssthresh + TCP_MSS;
t->sock.tcp.cwnd_count = 0;
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Addressed all review comments. + fixed 3 x dup to enter fast retransmit + fixed window scaling calculation + added capped budget for main poll
Improve TCP Tx fifo handling, wrap arounds and associated BSD socket calls. extend unit test coverage.