Jump to content
  • Advertisement
Sign in to follow this  
md_lasalle

Connect() in a thread ( Linux )

This topic is 3984 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

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.

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
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]

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!