After establishing a Modbus TCP connection between the Wiznet, acting as client and a peer acting as a server, if during a transmit from the client to server the connection is broken, i.e by removing the ethernet cable at the server end, no indication is given. Using Wireshark, we can see that the Wiznet attempts to re-transmit the packets and gives up after the configurable time period. Adding debug shows that the detected timeout is never propagated up to the caller who initiated the transmit.

With further debugging we noticed that the transmit callback handler is deleted immediately when the Sn_IR (Socket n Interrupt Register) [SEND_OK] bit is set. When the timeout later occurs, although the TIMEOUT bit in the Sn_IR register is set, it then attempts to call the callback handler but it has already been deleted by the SEND_OK case.

The following code shows a workaround for the above issue. The _transmitCallback has been moved from the SEND_COMPLETE to DATA_RECEIVED case and the callback is successfully called indicating timeout.