Sarthak-Pandey commented on PR #20702:
URL: https://github.com/apache/nuttx/pull/20702#issuecomment-6557581465

   Hi @casaroli and @acassis,
   
   Thank you for the detailed feedback. I have resolved both the TCP thread 
safety point at `net/inet/inet_sockif.c:1882` and added the active CAN 
multi-iov frame transmission & truncation run on `sim:can`.
   
   ### 1. Summary of Changes
   1. **TCP Thread Safety (`net/inet/inet_sockif.c:1882`)**:
      - Reverted the per-iov `inet_send()` loop. We now preserve the universal 
gather path in `inet_sendmsg()` across all configurations (including with write 
buffers). This submits all vector chunks atomically in a single `inet_send()` 
call under connection lock, completely eliminating the possibility of 
concurrent thread data interleaving between `iov` slices.
   2. **PR Description Corrections**:
      - Documented that `msg_iovlen == 0` returns `-EMSGSIZE` (matching the 
codebase and POSIX standard).
      - Updated the TCP section to describe the atomic gather path.
   3. **Active CAN Frame & Truncation Run on `sim:can`**:
      - Ran active CAN socket verification on `sim:can` with `can0` interface:
        - Multi-iov Gather Send: 3 `iovec`s (`can_id` 4B, `can_dlc` 1B, payload 
11B -> 16B CAN frame) transmitted cleanly.
        - Multi-iov Scatter Recv: 2 `iovec`s (8B + 8B -> 16B CAN frame) 
received and verified (`can_id == 0x123`, `can_dlc == 8`, payload matched).
        - Truncation Test: shorter `iovec` buffer (8B) received partial 
datagram with `MSG_TRUNC` set in `msg_flags`.
   
   ### 2. Comprehensive Test Matrix
   | Scope / Target | Platform | Result | Verification Notes |
   |---|---|---|---|
   | **Active CAN Frame Gather/Scatter** | `sim:can` 
(`CONFIG_SIM_CANDEV_SOCK=y`) | **PASS** | 3 iovs gathered -> frame sent; 2 iovs 
scattered <- frame verified (`can_id=0x123`, `dlc=8`). |
   | **Active CAN Truncation** | `sim:can` (`CONFIG_SIM_CANDEV_SOCK=y`) | 
**PASS** | Shorter iov buffer returns 8B and asserts `MSG_TRUNC` in 
`msg_flags`. |
   | **UNIX / Local Sockets** | Flat (`sim:tcploop`) & Kernel (`rv-virt:knsh`) 
| **PASS** | 3 iovs send -> 4 iovs recv with `MSG_WAITALL`. 100% data match. |
   | **UDP Datagram Sockets** | Flat (`sim:tcploop`) & Kernel (`rv-virt:knsh`) 
| **PASS** | Multi-iov send/recv + shorter iov truncation verification. |
   | **TCP Stream Sockets** | Flat (`sim:tcploop`) & Kernel (`rv-virt:knsh`) | 
**PASS** | Multi-iov atomic send across stream boundaries. |
   | **IOB Unit & Stress Testing** | Flat (`sim:tcploop`) | **PASS** | 10k 
throttled + 10k unthrottled iterations without leaks. |
   | **Existing Application (`tcpblaster`)** | Flat (`sim:tcploop`) | **PASS** 
| Streamed >5MB over TCP loopback with write buffers enabled. |
   
   ### 3. Execution Logs
   
   <details>
   <summary><b>sim:can Active CAN Frame & Truncation Run Log</b></summary>
   
   ```text
   nsh> ifconfig
   can0 Link encap:UNSPEC at UP mtu 72
        inet addr:0.0.0.0 mask:0.0.0.0
   nsh> net_iov_test
   
   ============================================================
      Apache NuttX Scatter-Gather (msg_iov) Verification Suite  
   ============================================================
   
   [TEST 1/4] UNIX Domain Stream Sockets (AF_LOCAL): [SKIP] (unconfigured)
   [TEST 2/4] UDP Datagram Sockets (AF_INET, SOCK_DGRAM): [SKIP] (unconfigured)
   [TEST 3/4] TCP Stream Sockets (AF_INET, SOCK_STREAM): [SKIP] (unconfigured)
   ------------------------------------------------------------
   [TEST 4/4] CAN RAW Sockets (AF_CAN, SOCK_RAW)
   ------------------------------------------------------------
     [PASS] can sendmsg(msg_iovlen = 0) returns -EMSGSIZE
     [PASS] can recvmsg(msg_iovlen = 0) returns -EMSGSIZE
     [PASS] can sendmsg(len != CAN_MTU) returns -EINVAL
     [PASS] can sendmsg gather (3 iovs -> 16 bytes frame)
     [PASS] can recvmsg scatter (2 iovs <- 16 bytes, verified ID=0x123 DLC=8)
     [PASS] can recvmsg truncation (shorter iov: ret=8, MSG_TRUNC set)
   
   ============================================================
     >>> ALL SCATTER-GATHER (IOV) TESTS PASSED! <<<
   ============================================================
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to