In article <6.1.1.1.0.20050907232834.05fd2910 / mail.the-arc.net>,
  Morgan <taria / the-arc.net> writes:

> I suppose because it's part of the only way I've found to get around the 
> lack of
> a someSocket.readallavailable - something that will give me *all* the data
> that can be read from the socket at the time I call it. (I could use recv with
> a number larger than anything I should ever have waiting for an argument,
> but that's crude. Admittedly, the workaround is also crude.)

Why you needs the all available data?

Even if you got the all data at the time, some data may be arrived
just after that.

> Sometimes the only way I have of being certain that I've gotten all of an
> incoming line is that I haven't been sent anything more. So, in place of
> a readallavailable function, I have this procedure (which I have yet to code,
> but I think should work):
>
> 1. Get a chunk of data with recv. At this point, I don't care if it blocks.
> 2. Add received data to a  buffer.
> 3. Check to see if there's any data waiting.
> 4. If there is, go back to step 1. If there isn't, go on.
> 5. Now being sure that the buffer contains all data currently
> available, the program can process it.

You can't assume that the all data is in the buffer because
some data may be arrived between 4 and 5.

Is it acceptable?

If it is acceptable, the program can process the data incrementaly;
for each 4K bytes or a line or another.

If it is not acceptable, I think it's a problem of the protocol.

> I tried doing something like this (or at least what I think you're
> referring to) in the program I'm working on now. (Using Fox toolkit
> via FXRuby.) However, I couldn't get it to work right on my own, and
> my message here asking for help got no replies...

Hm.  GUI library.  I understand why your program can't block.

> In any case, the method called by the framework to handle the
> event will still have to deal with the "do I have all the data?" issue.

Yes.  The framework notify that some data (or EOF) available.
It doesn't notify how much data available.

However the framework should notify readability until kernel has no
data.  So it is no problem that the callback doesn't process the all
data.  If the callback process 1byte or more at once, all data will be
processed.

> It can do the job, yes. But it also seems like overkill for someone
> who's only interested in one object. And it'd be a lot easier to read
> something that simply calls a method on the socket of concern.

I'm not sure that Ruby should encourage to read all data available.
-- 
Tanaka Akira