Ben Morrow wrote:
>># the if{} block runs only in the parent process
>>if ($kidpid) { # copy the socket to standard output
>> print "READ ...$EOL" if $V>1;
>> while (defined ($line = <$server>)) {
>
>
> Here is your problem. <$server> will not return until it reads a
> newline. You either want to set $/ to \1 (which will read a byte at a
> tyme: not very efficient) or set non-blobking mode and use
>
> while (read $server, $line, 1024) {
>
> ; or maybe sysread instead.
Well, I was wondering about that. I grepped and googled for
everything I could find on the topic, and found lots and lots
of advice that !| or one of the autoflush() calls would solve
all my problems. I kept thinking that those undo the buffering
on the sending end, but I don't see any evidence that it can't
also be a problem on the receiving end.
So I guess all those FAQs and RTFMs are just red herrings, and
I was guessing right all along. I wonder why I never ran across
any comments about this? Others have had to stumbled across the
same problem. There's gotta be a lot of people trying to send
data across TCP links in perl, right? And data isn't always in
the form of ASCII text with newlines at the end of every data
object, right?
Anyway, thanks for the advice. I think I'll try setting nonblocking
and use sysread(). Maybe I can copy some of my C code, and add a
few $'s, to get the corresponding perl code. Or maybe I won't figure
out how to set nonblocking, and I'll be back with another dumb
question soon.