connect() timeout change
Can the connect() function have its timeout changed? on redhat its about 3 minutes and I want to change that to about 10 seconds.
|
the solution is using nonblocking i/o and select. here is the function i use:
Code:
//do a nonblocking connect |
ill give that a try, Thanks.
|
im afraid that didnt work ,infamous41md. it compiled alright, but given a 10 second timeout it still waited < 1 second and didnt connect to a valid host im not sure whats wrong
|
well i use it everyday, so im pretty sure it works :D could i see how u used it? u say it returned right away? you should be checking the errror return for -1 and calling perror() if it is.
|
connect() will return an immediate failure if it is able to determine that it can't establish the connection. This is often the case when you are trying to connect to a socket on the same machine.
The function given above will wait _up to_ timeout seconds. In theory, you could change it to retry every now and then until your timeout value is exhausted. |
:(
well, I did try your code infamous41md , and it compiles OK, but when I use it, the timeout comes after 333 sec, while when I used usuall connect, timeout came after 189 sec....
Code:
J. |
oh, I forgot:
Code:
int s; |
I believe you can use setsockopt() with the SO_RCVTIMEO or SO_SNDTIMEO options. I'm not sure if those settings have any effect on connect(), but it should give you a place to look ;)
|
well, I want to do that under Linux...
|
add this:
ts.tv_usec = 0; right below ts.tv_sec = timeout |
thx
:D thx, now it works fine
J. |
All times are GMT -5. The time now is 09:39 AM. |