Forsaken has asked for the wisdom of the Perl Monks concerning the following question:
problem is as follows: I use a combination of Socket and IO::Select, quite classic really. I open a number of socket connections using this little snippet:
and then stuff the filehandle into IO::Select so I can perform the classic select loop to check which filehandles have data available. However, what I'm trying to do now is to implement a detection system for when a socket has died. Having read the documentation for IO::Select my first impression was that IO::Select->has_exception() would be the perfect tool to do so but for some reason it refuses to give me back anything, even though I am absolutely sure that the connection is dead on the other side. Any suggestions or ideas?sub makecon { my($self, $server, $port) = @_; my($iaddr, $paddr, $filehandle); my $proto = getprotobyname('tcp'); unless($iaddr = inet_aton($server)) { carp "No host found: $server"; + return; } $paddr = sockaddr_in($port, $iaddr); unless(socket($filehandle, PF_INET, SOCK_STREAM, $proto)) { carp "so +cket failure: $!"; return; } unless(connect($filehandle, $paddr)) { carp "connect failure: $!"; r +eturn; } return $filehandle; }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Knowing when a socket connection is dead
by castaway (Parson) on Jul 29, 2005 at 10:34 UTC | |
by kscaldef (Pilgrim) on Jul 29, 2005 at 16:17 UTC | |
|
Re: Knowing when a socket connection is dead
by metalgear119 (Acolyte) on Jul 29, 2005 at 12:29 UTC | |
|
Re: Knowing when a socket connection is dead
by kscaldef (Pilgrim) on Jul 29, 2005 at 16:11 UTC |