Re: Nonblocking and/or win32



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




.



Relevant Pages

  • Re: COmpact Framework Network Sniffing
    ... the UI with a Compact Framework application. ... code) to capture the packets and forward them, ... //For sniffing the socket to capture the packets has to be a raw ...
    (microsoft.public.dotnet.framework.compactframework)
  • Re: Slow network?
    ... There is an object called 'endpoint' on both sides, ... outgoing message queues. ... reading/writing messages from/into the socket object, ... raise SystemExit ...
    (comp.lang.python)
  • Re: Nonblocking and/or win32
    ... Add received data to a buffer. ... The framework notify that some data available. ... > something that simply calls a method on the socket of concern. ...
    (comp.lang.ruby)
  • Slow network?
    ... There is an object called 'endpoint' on both sides, with incoming and outgoing message queues. ... The endpoint is running two separate threads - those are dedicated for reading/writing messages from/into the socket object, ... My friend tried to do the same thing in Java, and he said that he could reach 1000 messages/sec. ...
    (comp.lang.python)
  • Re: tasksing and TCP sockets
    ... Does that mean e.g. to set the main task to 10 and the second task to ... > on socket completions, not polling for them. ... I find the commercially supported GNAT to be ... Redesign to be waiting on ...
    (comp.lang.ada)