...

View Full Version : Signals to interrupt threads on Windows



member887
11-14-2008, 08:15 PM
Hi -

Not sure where this post would fall under so I'm posting it under general programming.

I am working on a client application that establishes connection to a server and then waits for server data. But if there is no data to read in 30 seconds, I would like the application to timeout. How do I simply interrupt the connection and return without terminating the process on Windows? On Unix, I can use the alarm()/signal() call. For Windows, I found the SetTimer() to time the hang, but how do I send a signal to interrupt the connection? Any suggestions or comments greatly appreciated.

Thanks,
member887

oracleguy
11-15-2008, 01:45 AM
How are you establishing the connection to the server? Using winsock?

member887
11-17-2008, 05:24 PM
I believe so... Sorry I was just giving a simple scenario in my previous message. This is actually an SSL connection. I am using the OpenSSL BIO_do_connect() for the connection establishment. And it is hanging in BIO_do_connect(). I believe it is hanging at the SSL handshake (no, this is not an OpenSSL bug). So I just wanted to interrupt the connection when this happens.

In the current solution, I would call BIO_get_fd() to get the socket of the SSL connection and call socketclose() after the timeout I set. But I'm just wondering if there is a better way to interrupt the connection for Windows. On Unix, I can easily use the alarm() for timeout and signal() to catch the SIGALRM signal.

Thanks,
member887

oracleguy
11-19-2008, 07:29 PM
So I take it the BIO_do_connect is a blocking call until the connection is established?

Is there an asynchronous version of that function? Then it wouldn't be a blocking call and you could just wait until timeout and if the function hasn't triggered the callback function, abort the connection.

Also I think there is an equivalent of alarm() on Windows if you install the cygwin (http://www.cygwin.com/) library.

member887
11-24-2008, 10:27 PM
Thanks! I went with aborting the connection upon timeout.

-member887



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum