Re: Nonblocking and/or win32
- From: Morgan <taria@xxxxxxxxxxx>
- Date: Thu, 8 Sep 2005 13:57:27 +0900
Tanaka Akira wrote:
> someSocket.incoming_data_waiting?
I'm not sure why people want a such method.
What is a situation you need the method?
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'd also love to see a method that would tell me how many bytes are waiting to be read at the moment. But I wouldn't be surprised if that's not feasible for some reason or another.
> 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.
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.
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.
Threads, though powerful, are rather annoying to deal with sometimes. In the program I'm working on now, they're probably the best way of handling things anyway, but I'd like to have a way of working with sockets that doesn't force me to use them when they don't suit my needs.
So I guess your program has another situation I don't imagine.
However it is possible to implement the method by IO.select.
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.
-Morgan
-- No virus found in this outgoing message. Checked by AVG Anti-Virus. Version: 7.0.344 / Virus Database: 267.10.18/91 - Release Date: 09/06/2005
.
- Follow-Ups:
- Re: Nonblocking and/or win32
- From: Tanaka Akira
- Re: Nonblocking and/or win32
- From: Bill Kelly
- Re: Nonblocking and/or win32
- References:
- Re: [ANN] EventLoop 0.0.20050825.1600
- From: Bill Kelly
- Re: [ANN] EventLoop 0.0.20050825.1600
- From: Tanaka Akira
- Nonblocking and/or win32 (was: Re: [ANN] EventLoop 0.0.20050825.1600)
- From: Bill Kelly
- Re: Nonblocking and/or win32 (was: Re: [ANN] EventLoop 0.0.20050825.1600)
- From: Bill Kelly
- Re: Nonblocking and/or win32 (was: Re: [ANN] EventLoop 0.0.20050825.1600)
- From: Tanaka Akira
- Re: Nonblocking and/or win32 (was: Re: [ANN] EventLoop 0.0.20050825.1600)
- From: Morgan
- Re: Nonblocking and/or win32
- From: Joel VanderWerf
- Re: [ANN] EventLoop 0.0.20050825.1600
- Prev by Date: Re: Need help finding decent IDE/development environment for Windows
- Next by Date: WIN32OLE doesn't seem to support UTF-8.
- Previous by thread: Re: Nonblocking and/or win32
- Next by thread: Re: Nonblocking and/or win32
- Index(es):
Relevant Pages
|