I just asked this question elsewhere, and got a good working response. Below
is my trivialised code:

 my $BytesRead = $sock->sysread($buffer,1024);
       if (!defined($BytesRead))
       {
           print "WARNING: Connection lost!\n";
           exit;
       }

Because sysread is blocking (I don't know how to unblock it), use IO::Select
to test for data before calling sysread.

I'm working on a clean socket reading method. Write me if you've got it
before me.

----- Original Message ----- 
From: "Ivan Heffner" <[EMAIL PROTECTED]>
To: "Philip M. Gollucci" <[EMAIL PROTECTED]>
Cc: <modperl@perl.apache.org>
Sent: Tuesday, December 20, 2005 9:10 AM
Subject: Re: How do I check a socket to know it is not closed?


> I tried that and it didn't work.  I have this code:
>
>     my $len = $sock->recv($buff, $want);
>
>     warn "got the message\n";
>     sleep 10;
>     warn "sending the response\n";
>
>     my $wlen = eval { $sock->send( "I heard $buff\n" ) };
>     if ($@) {
>         warn "They hung up!\n";
>     }
>     else {
>         warn "sent $wlen bytes\n";
>         $sock->send( "It's been good talking to you.  Good-bye\n" );
>         $sock->close();
>     }
>
>
> I get the following in the log:
>
> got the message
> sending the response
> sent 13 bytes
> [Mon Dec 19 17:07:23 2005] [error] APR::Socket::send: (32) Broken pipe
> at /home/iheffner/proto/lib/ProtoConnection.pm line 55
>
> I need to know that the client app just stopped listening.  There is
> no explicit timeout on the socket.
>
> Ivan
>
> On 12/19/05, Philip M. Gollucci <[EMAIL PROTECTED]> wrote:
> > On Mon, 19 Dec 2005, Ivan Heffner wrote:
> > > Any ideas or pointers on how to do this.  Even a redirect to some
> > > (helpful) docs (Not the "Possible values: XXXX" docs) would be
> > > helpful.
> >
> > t/protocol/TestProtocol/echo_timeout.pm
> >
> >
> > ------------------------------------------------------------------------
> > "Love is not the one you can picture yourself marrying,
> > but the one you can't picture the rest of your life without."
> >
> > "It takes a minute to have a crush on someone, an hour to like someone,
> > and a day to love someone, but it takes a lifetime to forget someone..."
> >
> > Philip M. Gollucci ([EMAIL PROTECTED]) 301.254.5198
> > Consultant / http://p6m7g8.net/Resume/resume.shtml
> > Senior Software Engineer - TicketMaster - http://ticketmaster.com
> >
> >

Reply via email to