Connect() in a thread ( Linux )

Started by
1 comment, last by md_lasalle 16 years, 9 months ago
I'm trying to make a timeout on my connect(), which i run in a thread. When i reach my timeout, i simply kill the socket that connect() is working on. On Windows, it works just fine, connect() returns an error, the threads finishes and everyone is happy (especially me) But on linux, using POSIX Threads, connect() never returns an error. Do i need to lock my threads, use mutex or w/e since i'm modifying the socket file descriptor ? I don't have a good thread background, and since in Windows it does so much for you, i feel kinda lost with Linux threading. Thanks for any help.
Advertisement
Did you consider setting the socket to non-blocking, calling connect() and then using select() to check if the socket is writable? select() has the time out functionality built-in to it.
yes i know, but i don't want to block on connect(), i want the user to be able to interrupt the connection process.

you think i could poll it with a timeout of 0, until select tells mes the socket is ready for writing ?

** EDIT : It works perfectly this way! thanks

[Edited by - md_lasalle on July 26, 2007 6:58:33 PM]

This topic is closed to new replies.

Advertisement