Reputation: 1659
I would like my Winsock TCP connect() call to block with an infinite timeout.
Questions: 1. How may I do this?
Thank You, Dave
Upvotes: 1
Views: 3251
Reputation: 122769
To answer the second part of your question:
From a functional perspective, my desire stated above is exactly what I need. Is there any reason from a technical perspective this would be a bad idea?
You can only detect the difference between a broken TCP connection and a connection that's not sending you anything by writing to it (see this answer). Reading nothing can mean either that the connection is broken or that nothing is being sent to you. Timeouts are useful to detect (or force) such disconnections, so as to release resources. (You could use TCP Keep-alive too to detect a disconnection, but the effect is very similar to a timeout.)
If the protocol you're planning to use writes sufficiently regularly from the side where you want to disable timeouts, this may not matter to you, otherwise, you may simply end up in a situation where you're expecting something to come from the other end forever (since it may have disconnected abruptly).
Upvotes: 2
Reputation: 206929
If you want to wait forever, just retry if the connect
times out.
The timeout is quite fundamental to how TCP works. You can tweak your machine's settings (see for example: Which is the default TCP connect timeout in Windows?), but that's not a good idea (affects all TCP connections).
Upvotes: 5