From: Robert Klemme Date: 2008-07-02T06:52:08+09:00 Subject: Re: in select: interrupt On 01.07.2008 17:25, Mark Firestone wrote: > On Tue, Jul 1, 2008 at 4:18 PM, Robert Klemme > wrote: >> Laughing is usually not my reaction to this kind of mess... >> > Heh. So, what is your usual reaction? Tears? Dispair? You don't want to know. > It's a mess > I intend to clean up, I assure you... (; That's good to hear. There are too many around creating even worse messes and not caring. Usually other have to clean up after them and remove all the bugs. Worst of all initially they have to spend numerous hours understanding what the poorly written code was supposed to do in the first place. Often it's just lack of experience but even more often it seems that it's just carelessness - probably because they do not take pride in what they do or just don't like their work and are just in SE for the money. >> You are doing at least one mistake: you #select with a timeout but do >> not check return values. With a timeout #select might return without >> anything to read - simply because time has passed. > > Shouldn't it return nil in that case? Yep, I think you are right. Sorry for that. But given the fact that you are reading from a single stream only why do you use select at all - especially since you do an endless loop anyway? I mean, you could just do blocking reads, couldn't you? >> Also, as I said, I'd start with the regular #read and not use #sysread. > > Ok. What's the difference? http://www.ruby-doc.org/core/classes/IO.html#M000484 I believe it will at least circumvent Ruby's buffering. Rdocs are not very exhaustive and I don't have my copy of the Pickaxe handy but I'd always first use the "regular" methods #read and #write. Kind regards robert