Ok, if you're using sockets I strongly recommend you ALWAYS using sysread and syswrite as they baypass standard IO buffereing.
Be careful with sysread, it cand and will return partial reads, you MUST be prepared for that. Unless you want your program to block on sysread, you should use IO::Select. Now, from Stein's nEtwork Programming with Perl, as File handle is ready for reading when: 1. There is at least 1 byte of data in the file handle's input buffer, 2. There is an EOF on the file handle, the next call to sysread will return 0 in this case. With normal files this occurs at EOF, with sockets this occurs when the remote peer closes the connection, 3. There is a pending error on the socket. The next sysread call will return undef and the error will be in $!. So, what you are interested in is 2 or 3 or both. Code accordingly. Cheers, John > -----Original Message----- > From: [EMAIL PROTECTED] > [mailto:[EMAIL PROTECTED] On > Behalf Of Foo Ji-Haw > Sent: Monday, December 19, 2005 11:28 AM > To: [email protected] > Subject: how to detect a disconnected socket? > > > Hi all, I have the same issue (see subject title) as Trever in the > mailing list. Unfortunately reading through the mailing list > archive it > seems that his problem was not resolved. I'm hoping to have > better luck > with you guys. :) > > Basically, I need to know if my IO::Socket::INET socket connection is > disconnected by the remote peer, in which case I will have to > close the > socket, reuse the thread for the next connection. > > There were some mentions on using IO::Select: > my $select = IO::Select->new($sock); > while ($select->can_read) > { > ... > } > > But it seems that it does not help in detecting the connection state > (it keeps returning 1). > > Any ideas/ hints will be appreciated. Thanks. > _______________________________________________ > Perl-Win32-Users mailing list > [email protected] > To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs > _______________________________________________ Perl-Win32-Users mailing list [email protected] To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs
