Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 5 of 5
  1. #1
    New to the CF scene
    Join Date
    Nov 2008
    Posts
    6
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Signals to interrupt threads on Windows

    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

  • #2
    Rockstar Coder
    Join Date
    Jun 2002
    Location
    USA
    Posts
    9,074
    Thanks
    1
    Thanked 328 Times in 324 Posts
    How are you establishing the connection to the server? Using winsock?
    OracleGuy

  • #3
    New to the CF scene
    Join Date
    Nov 2008
    Posts
    6
    Thanks
    1
    Thanked 0 Times in 0 Posts
    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

  • #4
    Rockstar Coder
    Join Date
    Jun 2002
    Location
    USA
    Posts
    9,074
    Thanks
    1
    Thanked 328 Times in 324 Posts
    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 library.
    OracleGuy

  • Users who have thanked oracleguy for this post:

    member887 (11-24-2008)

  • #5
    New to the CF scene
    Join Date
    Nov 2008
    Posts
    6
    Thanks
    1
    Thanked 0 Times in 0 Posts
    Thanks! I went with aborting the connection upon timeout.

    -member887


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •