in reply to Re: IO::Socket client does not detect when server network connection dies
in thread IO::Socket client does not detect when server network connection dies
> Your recursive call is weird. You can chew a lot of stack space this way and for nought. Also if connect is failing due to something other than the timeout, your code could bombard the poor server with a huge number of requests and very quickly and all the while burning lots of stack. A simple while loop should suffice, like this or whatever you want anything except pushing deeper into the stack.
Ditto. As ugly as it may seem, you need to institute a maximum number of times to retry (ie, *not* infinite recursion) and if that limit is reached, you are throwing a significant error and/or informing the CLIENT user. It also makes much sense to use a delay of some seconds in this loop, so you don't get bombed by the client.
> See Knowing when a socket connection is dead
The bit in the first reply by "castaway" is the tish: It's dead (disconnected), when can_read() indicates data available, but reading from it gives you no bytes. If you are paranoid like me you also give this a few chances in a loop, but regardless: that is the ONLY way to detect a dropped connection. Read() etc will not necessarily return an error.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^3: IO::Socket client does not detect when server network connection dies
by Marshall (Canon) on Jul 12, 2011 at 02:20 UTC |