Alejandro Santillan wrote:
>>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.
>
>
> It seems that increasing the buffer more thant 1024 didn't help in all
> cases. It seems that this stream of data comes in several packets and the
> terminator string is !END!
> I've tried reading one byte at a time, using an $i as offset, and checking
> whenever the END pattern showed up
>
> my $buffer;
> $i=1;
> while($buffercomplete=~/END/){
Don't you want !~ instead of =~ ?
> $bytes = sysread ($handle, $buffer, 1,$i);
> $buffercomplete=$buffercomplete.$buffer;
> $i++;
> }
> return $buffer;
>
> but it doesn't read a line,
What is in $i after the read ? What should it be ?
> whereas:
>
>>>my $buffer;
>>>my $bytes = sysread ($handle, $buffer, 1024);
>>>if (not defined $bytes or $bytes < 0) {
>>>#err
>>>print "error!!!";
>>>} elsif ($bytes == 0) {
>>># EOF
>>>}
>>>return $buffer;
>
> does read seven lines, and increasing the 1024 to 8192 the reading is the
> same, and it does not include the !END! pattern
I don't follow what you're saying here. If you're not getting the
EOR indicator, try a bigger read or read a second time if you don't
get it in the first buffer. Do a select before the read if you
don't want to block. How much data do you get on the first read ?
How big is the full record supposed to be ?
Please don't CC me on your replies.
_______________________________________________
Perl-Win32-Users mailing list
[email protected]
To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs