good chemistry is complicated, and a little bit messy -LW |
|
PerlMonks |
Re: Handling server socket error and reconnectby thospel (Hermit) |
on Nov 09, 2004 at 01:31 UTC ( [id://406256]=note: print w/replies, xml ) | Need Help?? |
Writing to a closed socket causes a SIGPIPE, which is a signal, not an exception. So you have to handle that somewhow, ignore is usually simplest. Then writing to a closed socket becomes just a normal I/O error. Assuming we don't have to worry about the speed at which I/O progresses, the code becomes:
(warning, only minimally tested) updated: code didn't take into account that a write might still get out, and only the read will notice the close. Also be more paranoid about a bad server, only retry once and assume an immediate second failure is a sign of server problems. updated: make the looping on first call consistent too.
In Section
Seekers of Perl Wisdom
|
|