[En-Nut-Discussion] NutTcpConnect() with timeout

Harald Kipp harald.kipp at egnite.de
Thu Sep 26 13:42:05 CEST 2013

Hi Ole,

On 26.09.2013 11:03, Ole Reinhardt wrote:
>> I have:
>>      if(sock->so_state == TCPS_SYN_SENT)
>>       {
>>         if (NutEventWait(&sock->so_ac_tq, sock->so_read_to))
>>             return -1;
>>      }
> I had exactly the same idea.
> @Harald: What do you think, would this be a reasonable change?

Not as easy to solve as it may look first.

The connect initiates the SYN handshake in the background thread of the
TCP state machine. The state machine decides, if the host is reachable
or not.

Returning from NutTcpStateActiveOpenEvent() without informing the state
machine may introduce unforeseen race conditions.

It may work with Henrik's application, but at least needs extensive
testing before other "creative" application programmers run into
unexpected trouble.

One thing that I'm missing in Henrik's patch is, that the application
has no chance to determine the cause of the error. I'd suggest to set
ETIMEDOUT to distinguish this with EHOSTUNREACH set by the state machine.

A minor confusion is, that it Henrik uses the _read_ time out. So far,
we use the read time out value to define the accept() time out. Makes
sense to me, as we are waiting for external activity. But isn't
connect() the opposite of accept()? Shouldn't we use the write time out
here instead?



More information about the En-Nut-Discussion mailing list