B
Bill Kelly
From: "Bill Kelly said:^^^^^^^^ hang
I guess it must be something very basic I'm not aware of
about #eof? ... Because even:
hangs.
Is it not possible to check for EOF without blocking?
Regards,
Bill
From: "Bill Kelly said:^^^^^^^^ hang
I guess it must be something very basic I'm not aware of
about #eof? ... Because even:
hangs.
Is it not possible to check for EOF without blocking?
From: "Ara.T.Howard said:[ahoward@localhost ~]$ strace ruby a.rb 2>&1
...
...
...
read(3
and, from io.c: [...]
ch = getc(fptr->f); // look here !!! [...]
anyhow... it sure makes sense that it'd block though...
Bill Kelly said:Is it not possible to check for EOF without blocking?
I documented the blocking behavior of IO#eof?. I hope it reduces
confusion about IO#eof?.
Morgan said:Hmmmm...
Correct me if I'm wrong, but using eof? on a socket would be rather
useless, wouldn't it?
I'd *really* like to find something that will just tell me if there's data
waiting on a socket. Something I can use like
someSocket.incoming_data_waiting?
And if there's something I can read, I'll get true, and otherwise I'll get
false. But nothing I've tried seems to work that way.
Morgan said:Correct me if I'm wrong, but using eof? on a socket would be rather
useless, wouldn't it?
I'd *really* like to find something that will just tell me if there's data
waiting on a socket. Something I can use like
someSocket.incoming_data_waiting?
And if there's something I can read, I'll get true, and otherwise I'll get
false. But nothing I've tried seems to work that way.
Tanaka said:I'm not sure why people want a such method.
What is a situation you need the method?
If it returns false, your program cannot have data from the socket.
So your program cannot do about the data. If your program has
something to do in such case, there should be some work which doesn't
depend the data.
If the work is done by other threads, the blocking behavior is
appropriate because the other threads is run at the blocking time.
If the program use a event driven framework, the readability test
should be done by the main event loop in the framework. So the
program don't need the method.
So I guess your program has another situation I don't imagine.
However it is possible to implement the method by IO.select.
From: "Morgan said:(I could use recv with
a number larger than anything I should ever have waiting for an argument,
but that's crude.
From: "Bill Kelly said:def TCPSocket.read_all_available
Morgan said: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.)
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.
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...
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.
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.
Want to reply to this thread or ask your own question?
You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.