user2485149
user2485149

Reputation: 91

How to solve Connect() time-out issues on blocking socket(for SSL handshake)?

This type of question is(with a lot of variations) kinda answered but.. I do need a blocking connect(i'm using SSL)on a socket, that i can set a time-out and maximum number of retries and all that is necessary for never lasting more than t seconds.

I just hope there is some thing i can set in the OS(linux: Ubuntu/CentOS) or some way to do this in code(C) w/o going for an ugly, artificial way like select wait, timeout events added to epoll that close the socket. thank you.

Upvotes: 0

Views: 2056

Answers (1)

gst
gst

Reputation: 817

The simplest way to do this is to use alarm system call before and after a connect call and to handle Alarm signal, but this is not the best and most useful way. The better and recommended way is to use a non-blocking socket and use poll or select system calls to handle different stages of making a connection. But if you don't want to use Non-blocking IO your only way is to use alarm.

For a tutorial about using non-blocking sockets refer to : http://developerweb.net/viewtopic.php?id=3196

For more information about what happens during a connect call refer to: http://www.madore.org/~david/computers/connect-intr.html

Upvotes: 1

Related Questions