Archived

This topic is now archived and is closed to further replies.

Sockets Question

This topic is 5234 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 think this was asked and answered before but the search button isn''t working for some reason so I''ll ask again. I currently have a thread that calls recvfrom on a blocking socket. If nothing is there to be received then the thread blocks and no CPU time is used up (a good thing). However, I am noticing that the thread is not exiting when the rest of the program does. The thread function is while loop while (bKeepThreadsAlive) { //Do stuff //call recvfrom() and block till info arrives } So, when I set bKeepThreadsAlive to false, my threads aren''t always shutting down. I''m pretty sure they shut down correctly if there is info to be received and the thread function can finish its processing. My send thread shuts down correctly but i only call send when I know there is information to be sent so it doesn''t block even though it is considered a blocking call. I''ve looked at non-blocking but polling a socket like that is supposed to eat up CPU cycles. Asynchronous is not an option (working on Linux). Select would probably eat up as much CPU as polling since it''s only dealing with a single socket. So any ideas on how I should handle this? I''m thinking that if I maybe set the socket to non-blocking then I can use Sleep() with a fitting time parameter to stop the polling from consuming too many CPUs. What do you guys think? Thanks, Webby

Share this post


Link to post
Share on other sites
closesocket(); it pulls the socket fd from under the sleeping thread, and recvfrom() falls over with an error code (EINTR). Works with both Windows and Unix.

-cb

[edited by - cbenoi1 on August 14, 2003 8:16:17 PM]

Share this post


Link to post
Share on other sites