Linux - NewbieThis Linux forum is for members that are new to Linux.
Just starting out and have a question?
If it is not in the man pages or the how-to's this is the place!
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
I have written simple TCP server-client programs in 'C' on my RHEL 5 64 bit.
I want to add SEND and RECEIVE timeout for this socket; so that if server is not responding in given time, request will get timeout instead of waiting in "recv" call.
But I failed to do so. can anybody help around it OR can redirect me to some link that will explain this.
But this you tell about connect;
1) Is this applicable to "recv" and "send" system calls as well.
2) Is there any other way, other than signal handling; like we dose in case of normal sockets as follows,
it should be applicable to send & recv functions i have not checked, but one thing if you apply timeout it will not connect then how will it proceed towards send & recv functions ?
yes that does make sense, I told you that alarm should work on send and recv functions.
Code:
There are three ways to place a timeout on an I/O operation involving a socket.
1. Call alarm, which generates the SIGALRM signal when the specified time has
expired. This involves signal handling, which can differ from one implementation
to the next, and it may interfere with other existing calls to alarm in the process.
2. Block waiting for I/O in select, which has a time limit built in, instead of blocking
in a call to read or write.
3. Use the newer SO_RCVTIMEO and SO_SNDTIME) socket options. The problem
with this approach is that not all implementations support these two socket options.
Each is appropriate, depending on the specific circumstances. I hope this helps.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.