🎉 Celebrating 25 Years of GameDev.net! 🎉

Not many can claim 25 years on the Internet! Join us in celebrating this milestone. Learn more about our history, and thank you for being a part of our community!

how do you get out of a blocking recv() call?

Started by
1 comment, last by evilchicken 22 years, 7 months ago
the recv is in a seperate thread btw, there has to be a better way of doing it, other then terminating the thread.
Advertisement
The Right Thing to do is to not let it block in the first place by making sure that you have data to read. To do that, you would use select(), which will block until something happens on the sockets (Note: plural) it is watching. And if you want to make it bail out on demand (and not with a timeout), you plug in another ''control'' socket, which will cause a shutdown when data is received on it.

For more details on the use of select, search the discussions, that question has come up before.
"Debugging is twice as hard as writing the code in the first place. Therefore, if you write the code as cleverly as possible, you are, by definition, not smart enough to debug it." — Brian W. Kernighan
TerminateThread is evil, don''t even think of using it.

Your two options are to use select with a timeout like Fruny suggested or to close the socket that the the thread is waiting on. And I''m not sure if the second method is portable and/or safe.

-Mike
-Mike

This topic is closed to new replies.

Advertisement