The troublesome code is not the execCmdSn; that returns instantly. The problem is back in Client::connect()
while (status() != SnSR::ESTABLISHED) {
delay(1);
if (status() == SnSR::CLOSED) {
_sock = MAX_SOCK_NUM;
return 0;
}
}
That is where you would put the patch suggested by robtillaart...but, it's so much easier than that!
The simple fixarduino-0021\libraries\Ethernet\utility\w5100.cpp, add 2 lines to make the init function look like this
void W5100Class::init(void)
{
delay(300);
SPI.begin();
initSS();
writeMR(1<<RST);
writeTMSR(0x55);
writeRMSR(0x55);
setRetransmissionTime(0x07D0);
setRetransmissionCount(3);
for (int i=0; i<MAX_SOCK_NUM; i++) {
SBASE[i] = TXBUF_BASE + SSIZE * i;
RBASE[i] = RXBUF_BASE + RSIZE * i;
}
}
setRetransmissionTime sets the Wiznet's timeout period, where each unit is 100us, so 0x07D0 (decimal 2000) means 200ms.
setRetransmissionCount sets the Wiznet's retry count.
A retry count of 2 or 3 makes the connect function fail really quickly.
Hope that helps.
Ben
Edit:
The simpler fixYou don't even need to modify the library code. In your sketch, add this include:
#include <utility/w5100.h>
then, in your setup, after you call Ethernet.begin(), add the following two lines:
W5100.setRetransmissionTime(0x07D0);
W5100.setRetransmissionCount(3);
That gives me a 3 second timeout on a bad server connection.