Linux - GeneralThis Linux forum is for general Linux questions and discussion.
If it is Linux Related and doesn't seem to fit in any other forum then this is the place.
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.
Introduction to Linux - A Hands on Guide
This guide was created as an overview of the Linux Operating System, geared toward new users as an exploration tour and getting started guide, with exercises at the end of each chapter.
For more advanced trainees it can be a desktop reference, and a collection of the base knowledge needed to proceed with system and network administration. This book contains many real life examples derived from the author's experience as a Linux system and network administrator, trainer and consultant. They hope these examples will help you to get a better understanding of the Linux system and that you feel encouraged to try out things on your own.
Click Here to receive this Complete Guide absolutely free.
I am implementing a peer-to-peer program: When a computer A receives “get file XXX” from stdio, it broadcasts (floods) a request packet to ask others. Both Computer B and C have the file so they send back responses. Computer A pick up B and sends confirm to B. at the same time, it creates a server socket to listen to connection. After Compute B receives the confirm from A, it creates a client socket to connects to A.
I set timeouts to both request and confirm packets. If no response is received by A after timeout, A needs to flood a new request packet again. Otherwise, A cancels timeout of the request. For the same reason, if B does not connect to A, A will send a confirm to C so that C can connect to A
My Questions: How to set timeout?
a. I can use select(). But since I already put a select() with timeout parameter as NULL in a while loop to monitor stdio, request, confirm/response packets, it seems that there is no place to put other selects with timeout parameters。
b. I can use alarm(). But there is no way to know, which request/confirm of which file the alarm() is for. And if I cancle a timeout using alarm(0), other timeout using alarm() is also canceled.
c. I also thought about using fork（）+ select(): But after the child process is terminated, how do I know it is terminated because of timeout or because response or connection is received? Besides, If it is terminated because of timout, In which part of program should I re-flood the request or re-send the confirm packet?
I want to solve the problem and need your help. Can any guru answer the question? Thanks
Please post your thread in only one forum. Posting a single thread in the most relevant forum will make it easier for members to help you and will keep the discussion in one place. This thread is being closed because it is a duplicate.