[En-Nut-Discussion] TCP connect timeout added

Ole Reinhardt ole.reinhardt at embedded-it.de
Fri Jan 10 18:43:16 CET 2014


Hi all,

I added a configurable timeout to NutTcpConnect() in SVN trunk rev. 5542

The socket write timeout is used for this purpose:

Usage:
======

uint32_t timeout = 5;
NutTcpSetSockOpt(sock, SO_SNDTIMEO, &timeout, sizeof(timeout));

if ((rc = NutTcpConnect(sock, rip, INETSERVERPORT)) == 0) {
   /* Reset the write timeout to infinite (or to whatever,
      for further communication.
    */
   timeout = 0;
   NutTcpSetSockOpt(sock, SO_SNDTIMEO, &timeout, sizeof(timeout));
   ...

   /* Do something here */

} else {

    if (NutTcpError(sock) == ETIMEDOUT) {
	/* Timeout on connect */
    } else {
        /* Connection refused */
    }
    ...
}

NutTcpCloseSocket(sock);

Please note:
============

Make sure, that you always call NutTcpCloseSocket(), even if
NutTcpConnect() returned a timeout.


I intensively tested this feature in a long term test with in total
50mio connections. These tests showed up the TCP statemachine race
condition I reported in my last mail. Beside if this, I did my best to
avoid any bad side-effects.

However, please also review this code :-)

Best regards,

Ole Reinhardt

-- 
kernel concepts GmbH            Tel: +49-271-771091-14
Sieghuetter Hauptweg 48         Mob: +49-177-7420433
D-57072 Siegen
http://www.embedded-it.de
http://www.kernelconcepts.de


More information about the En-Nut-Discussion mailing list