Re: Glib::IO->add_watch and reading the filehandle



Hi,

2008/7/17 muppet <scott asofyet org>:
The trick in C code is to mark the file as non-blocking, and read chunks until
read returns 0 bytes.  I can't take the time to experiment right now, but i'm
reasonably certain that this works in perl, as well.

Gah. I'm still thinking in Perl/Tk terms. I was trying to figure out
why the filehandle wasn't being picked up as 'still readable' instead
of looking for a lower level solution. I've been doing a lot of head
slapping lately....

Unless you're using datagram sockets, there is no guarantee that an entire
message showed up at once, so you always have to be able to handle partial
reads.

Partial reads aren't a problem (the main program just buffers the data
until it gets a whole message as long as the message so far is
structurally valid) it was just that sometimes that 'too big' message
wasn't followed by another message for a very long time, so the buffer
was never getting flushed.

If I use:

use Fcntl;
fcntl($FROM_CHILD, F_SETFL, fcntl($FROM_CHILD, F_GETFL, 0) | O_NONBLOCK);

that should do the trick.

Ta :)

MB



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]