> From: Gary
> 
> Bob McConnell wrote:
> >> From: Gary
> 
> >> For the record, this is what I did to get around the problem:
> >>
> >> ,----[ code ]
> >> | my $s = IO::Select->new($self->{_sock}); while (my @ready =
> >> | $s->can_read(1)) {
> >> |     my $recd = RECV_BUF_SIZE;
> >> |
> >> |     while ($recd == RECV_BUF_SIZE) {
> >> |         my $buf = '';
> >> |
> >> |         $self->{_sock}->recv($buf, RECV_BUF_SIZE, MSG_WAITALL);
> >> |
> >> |         $recd = length($buf);
> >> |         $ret .= $buf;
> >> |     }
> >> | }
> >> `----
> >> Note the added 'while' loop around the recv loop.
> 
> > Ok, this will append all of the full buffers and the first partial
> > buffer into a single string ($ret). If you are going to handle
> > multiple passes, make sure $ret is empty each time you enter the
loop.
> > It probably should be declared and initialized to an empty string
anyway.
> >
> >    my $ret = "";
> 
> It is. I left this out of the update (and changed the variable names
between
> the two versions, besides), so it's not so surprising you didn't see
that.
> 
> > Is there anything constant about your incoming messages? Are they
all
> > the same length, or is there a delimiter at the end you can test
for?
> 
> No, and yes. I could check for "</xml>" at the end I guess, but...
> ewww...  That layer should know SFA about what's coming through.

At some level you will need to look for that closing tag and be prepared
to handle both exception cases, a truncated message or parts of one or
more additional messages appended after that closing tag. This is the
streams nature of TCP, there is no way to avoid it.

In the case of the truncated or empty message being returned, you should
also find out if it was caused by the remote end closing the connection
or a network failure. Both require you to close the socket and try
again. But after the retry fails, the recovery procedures are very
different.

Bob McConnell


--
To unsubscribe, e-mail: beginners-unsubscr...@perl.org
For additional commands, e-mail: beginners-h...@perl.org
http://learn.perl.org/


Reply via email to