开发者

Select calls seems to not time out

HI Folks,

I have a threaded C++ program where up to three threads are calling select on a three separate socket descriptors waiting for data to become available. Each thread handles one socket and adds it to the readfds with a timeout of 300 seconds. After select returns if there is data available I'm calling recv to read it.

Is there anything that I need to be aware of with winsock and threads because for some reason after a number of hours the select calls all seem to be not timing out. Can a multi threaded program select from a number of threads without issue?

I know that I should have one thread listening to all three sockets however that would be a large change for this app and I'm onl开发者_如何学Goy looking to apply a bug fix.

cheers,

Martin.


Without some code, I can only make a guess. The most common reason for select timeouts to not work properly is that the struct timeval argument is not reset in every iteration of the loop. Some (all?) select implementations update the timeout parameter to reflect the amount of time spent blocking. However, this usually results in select not blocking.

Are you sure that select is the problem and you do not have something else going on like stack corruption, a memory leak, etc.?

Edit: I have used select from multiple threads on different sockets before under Windows without problems. I forgot to mention this in the initial post.


I'm assuming that it is ok to use the select on differnet threads because the following link says it is grand.

http://tangentsoft.net/wskfaq/intermediate.html#threadsafety

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜