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




Matthew Braid wrote:
Every so often it would stop working (ie, the helper process would
claim it sent a message, but the main process wouldn't act on it), and
after a lot of debugging it turned out that if an incoming message was
longer than 1024 characters the remaining part after the first 1024
characters wouldn't be handled until the _next_ message was sent - in
other words, if I sysread 1024 characters off a 1025
character-available stream, the Glib::IO watch doesn't still see the
file handle as readable, and so doesn't trigger the callback until
more data is pushed onto it. Unfortunately I can't use a while
(sysread(...)) in the callback cos then it hangs waiting for data.

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.

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.


-- 
muppet <scott at asofyet dot org>




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