socket read timeout

H

hg

Hi,

I am looking for the most efficient / cleanest way to implement a socket
read with timeout (Windows mainly but would be great if the same code
worked under *nix)

Tanks,

hg
 
H

hg

hg> My issue with that is the effect on write: I only want a timeout
on
hg> read ... but anyway ...

So set a long timeout when you want to write and short timeout when you
want to read.

Skip


Not bad .. thanks
 
S

Steve Holden

hg said:
My issue with that is the effect on write: I only want a timeout on read ...
but anyway ...
If you want selective timeout behaviour then yes, you should use select.

regards
Steve
 
S

skip

hg> My issue with that is the effect on write: I only want a timeout on
hg> read ... but anyway ...

So set a long timeout when you want to write and short timeout when you want
to read.

Skip
 
H

Hendrik van Rooyen

hg> My issue with that is the effect on write: I only want a timeout on
hg> read ... but anyway ...

So set a long timeout when you want to write and short timeout when you want
to read.

Are sockets full duplex?

I know Ethernet isn't.

- Hendrik
 
H

Hendrik van Rooyen

Yes. But you have to use non-blocking calls in your application to use
them as full-duplex in your code.

This seems to bear out the scenario I have described elsewhere in this
thread - I think its caused by the file handlers, but I don't _know_ it.
Don't know much, then, do you? ;-)

No not really - I easily get confused by such things as collisions...

: - )

- Hendrik
 
B

Bryan Olson

Steve said:
Yes. But you have to use non-blocking calls in your application to use
them as full-duplex in your code.

Hmmm... I'm missing something. Suppose I have one thread (or
process) reading from a blocking-mode socket while another is
writing to it? What stops it from being full duplex?
 
H

Hendrik van Rooyen

Hmmm... I'm missing something. Suppose I have one thread (or
process) reading from a blocking-mode socket while another is
writing to it? What stops it from being full duplex?

Elsewhere in this thread I wrote about my experience with a serial port,
where I can show that the "file handler" only does the write once the
blocking read completes - and the point at issue is if sockets are the same.

We regularly get questions about "my stuff does not come out" on
the group, and I wondered whether this effect is the underlying cause.

But I don't know about the sockets case, which is why I asked.

You raise an interesting point about a different process - my serial
experience is using threads. I have never tried mixing processes
on a serial port. Haven't a clue if its possible, or if the behaviour
will be different.

- Hendrik
 
S

Steve Holden

Hendrik said:
This seems to bear out the scenario I have described elsewhere in this
thread - I think its caused by the file handlers, but I don't _know_ it.


No not really - I easily get confused by such things as collisions...

: - )

Right, but collisions are *so* twentieth-century, aren't they. With a
properly-implemented switched infrastructure Ethernet interfaces can
transmit and receive at the same time.

regards
Steve
 
S

Steve Holden

Bryan said:
Hmmm... I'm missing something. Suppose I have one thread (or
process) reading from a blocking-mode socket while another is
writing to it? What stops it from being full duplex?
Nothing, I guess. I just didn't consider threaded code ...

regards
Steve
 
H

Hendrik van Rooyen

Steve Holden said:
Right, but collisions are *so* twentieth-century, aren't they. With a
properly-implemented switched infrastructure Ethernet interfaces can
transmit and receive at the same time.

This is true, while "A" and "B" are not simultaneously trying to address
"C" - Then you need something like store and forward, on the fly...

: - ) better known as "routing"...

Some (most?) of the little switches I have seen are too dumb even to
allow "A" to talk to "B" while "C" is talking to "D" - they just broadcast
the first "talker"'s message to all the "listeners" - little better than
active hubs, destroying the end point's hardware capability to talk and
listen at the same time.

I think the keywords here are "properly implemented" - its actually not a
trivial problem, as the switch has to know or learn who is where, and set
up paths accordingly, in real time. This is hard to do without store and
forward.

- Hendrik
 

Ask a Question

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.

Ask a Question

Members online

Forum statistics

Threads
473,774
Messages
2,569,598
Members
45,152
Latest member
LorettaGur
Top