Return-Path: william@bourbon.usc.edu Delivery-Date: Sun Oct 19 20:21:53 2008 X-Spam-Checker-Version: SpamAssassin 3.2.3 (2007-08-08) on merlot.usc.edu X-Spam-Level: X-Spam-Status: No, score=-2.3 required=5.0 tests=AWL,BAYES_00 autolearn=ham version=3.2.3 Received: from bourbon.usc.edu (bourbon.usc.edu [128.125.9.75]) by merlot.usc.edu (8.14.1/8.14.1) with ESMTP id m9K3LrL3004054 for ; Sun, 19 Oct 2008 20:21:53 -0700 Received: from bourbon.usc.edu (localhost.localdomain [127.0.0.1]) by bourbon.usc.edu (8.14.2/8.14.1) with ESMTP id m9K3UvQv025061 for ; Sun, 19 Oct 2008 20:30:57 -0700 Message-Id: <200810200330.m9K3UvQv025061@bourbon.usc.edu> To: cs551@merlot.usc.edu Subject: Re: Reg select() Date: Sun, 19 Oct 2008 20:30:57 -0700 From: Bill Cheng Someone wrote: > I have a question regarding the operation of the select syscall. If we add 3 > descriptors (say fd1 fd2 and fd3) to the "master set" descriptor from which > we will continuously poll to read data from and if there is data on all 3 to > be read, how will the data be serviced ? > > The code is something like: > > while( 1 ) > { > > // poll with select for data > > if( fd 1) > { > //serve fd1 > } > > else if (fd 2) > { > //serve fd2 > ) > ...... > ...... > } > > So if all fd's have data, then will it first serve fd1, loop back and then > serve fd2 , loop back and then serve fd3 ? I'm not sure what you meant. You asked, "will it first serve ...". The way you wrote your code (with "else if"), it will only one will be true. So, if you want to service all of them, you should change your code. But for your example, it's fine to server only one of them becuase next time you call select(), if should return right away since you have data ready to be read at the other 2 file descriptors. > Also, I was confused about what will happen if 2 or more nodes send data to > a single fd, say fd1. Is there an in-built queue ? How can the data of two different nodes wind up at the same fd? Your code is probably not structured correctly. You should probably come talk to me during office hours! -- Bill Cheng // bill.cheng@usc.edu