wengzhe commented on issue #13823:
URL: https://github.com/apache/nuttx/issues/13823#issuecomment-2497044806

   > 1. **TCP socket not closing after physical disconnection:**
   >    I discovered that physically disconnecting the network (e.g., 
unplugging the cable) doesn’t trigger the TCP protocol to detect the 
disconnection. The socket remains open. Surprisingly, reconnecting the cable 
quickly allows the same connection to resume data transmission. While this 
behavior has some use, it seems incorrect.
   
   Hi @seele404 , I agree that this behavior is incorrect. Normal behavior 
should be:
   1. When a cable is unplugged, `netdev_carrier_off` would be called (in your 
case, it seems to be in `encx24j600.c`)
   2. Then a `NETDEV_DOWN` would be triggered through `devif_dev_event` to the 
TCP layer.
   3. The TCP layer uses `tcp_monitor`, which is started (`tcp_start_monitor`) 
when `connect` or `accept`, to monitor events by assigning the callback 
`tcp_monitor_event` to handle them, the `tcp_monitor_event` finally calls 
`tcp_close_connection` to clear `_SF_CONNECTED` flag on the connection.
   4. Apps calling `send` goes into `psock_tcp_send` and should return an error 
because of `!_SS_ISCONNECTED`
   5. Besides, if you're using `NET_TCP_WRITE_BUFFERS`, the 
`psock_send_eventhandler` in `tcp_send_buffered.c` also monitors the 
`NETDEV_DOWN` event to clear existing send buffers on the connection (multiple 
callbacks can be both called for one event if they're both registered, but take 
care of the number of callbacks, e.g. configurations like 
`NET_PREALLOC_DEVIF_CALLBACKS`).
   
   I hope these would help.


-- 
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