Alejandro Santillan wrote:

> Bill, I was using your solution successfully to read several messages sent
> by the server, but when trying to work some request,
> which had a longer answer, your buffer only gets:
...
> How could I modify your routine, which is the following:
> 
> my $buffer;
> my $bytes = sysread ($handle, $buffer, 1024);
> if (not defined $bytes or $bytes < 0) {
> #err
> print "error!!!";
> } elsif ($bytes == 0) {
> # EOF
> }
> return $buffer;
> 
> In order to get the full answer and avoid the program to hang.

1) Increase the size of the read to more than 1024.
2) Optionally add a print on the error and EOF lines and return
-1 and 0 to the caller to indicate err and EOF.  Test for those
two conditions in the calling code and handle them accordingly
(at least indicate to the user what happened with a diagnostic
message).
3) Before doing the next read, make sure you do a select on the
socket to make sure that data is available.
4) Since the data in the buffer is in a stream, you will need to
find where each record begins and ends and possibly concatenate
data from two reads to complete a single record when the record
spans the read boundary.

_______________________________________________
Perl-Win32-Users mailing list
[email protected]
To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs

Reply via email to