Archived

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

linux: Socket question

This topic is 5245 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

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?

Share this post


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

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
you could always set an alarm() before read()ing

Share this post


Link to post
Share on other sites