Advertisement

linux: Socket question

Started by August 06, 2003 08:46 PM
2 comments, last by mr BiCEPS 21 years, 3 months ago
Hi, I would like to know if there''s a way of making a TCP socket timeout after it has been blocking, waiting to read for a while. I googled a little and it seems like I am supposed to setsockopt with SO_RCVTIMEO. Would this work with TCP sockets in linux? If so, how does one tell if the socket timed out, either completely or partially (got a part of the data it was waiting for but not all)? If I understand things correctly, a struct timeval parameter is also to be sent to setsockopt. Is this correct?
Ok, nevermind the above. It is definitely not the correct way to do it, especially considering SO_RCVTIMEO is apparently read-only.

I guess I just have redesign my classes to use select(). *sigh*
Advertisement
you could always set an alarm() before read()ing
Is it really a good idea to use alarm() in multithreaded programs?

This topic is closed to new replies.

Advertisement