[En-Nut-Discussion] Socket timeout (Was: no subject)

Cosmin Buhu lists at byteworks.ro
Sat Nov 6 09:05:32 CET 2004


---- Original Message -----
From: "Michael Svob" <michael.s at lfiinternational.com>
To: "Ethernut User Chat (English)" <en-nut-discussion at egnite.de>
Sent: Saturday, November 06, 2004 1:20 AM
Subject: [En-Nut-Discussion] (no subject)


> Hello,
>
> I have an application where I am connecting to the Ethernut from a PC
based
> client using a TCP/IP socket connection (I used the 'tcps' sample code as
my
> "template").  Everything works fine, so long as I shut down the PC client
> gracefully, which in turn sends a message to the Ethernut telling it to
> terminate the session.
>
> However, if I abruptly lose communication between the PC and the Ethernut
> (e.g. PC crashes or reboots), then I cannot reconnect to the Ethernut
> without resetting it.  I added a "keep alive" mechanism, whereby if the
> Ethernut thinks it's connected, it looks for a keep-alive message sent by
> the client on a regular basis.  If it fails to see this message for some
> time, it attempts to tear down the connection on its side so it can wait
for
> a new socket request.
>
> The problem is that in my ProcessRequests() function, fread() sits there
and
> happily blocks forever for data that never comes.  I would have expected
> that when the socket stream is closed (by my keep-alive watchdog thread),
> that fread would return due either to a read error, or end-of-file.
> However, this is not the case; fread() just waits indefinitely.
>
> Is there a straightforward way to get fread() to return from blocking so
> that program flow can continue?  Is there a better way to not only detect
> the loss of connection with the PC client, but more importantly close the
> connection on the Ethernut side?
>
> Thanks!!!
>
> Michael Svob
> LFI International



    Try NutTcpSetSockOpt with SO_RCVTIMEO option.

Regards,
Cosmin




More information about the En-Nut-Discussion mailing list