Return-Path: william@bourbon.usc.edu Delivery-Date: Tue Oct 28 16:04:59 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.4 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 m9SN4xH3009986 for ; Tue, 28 Oct 2008 16:04:59 -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 m9SNG7eX004151 for ; Tue, 28 Oct 2008 16:16:07 -0700 Message-Id: <200810282316.m9SNG7eX004151@bourbon.usc.edu> To: cs551@merlot.usc.edu Subject: Re: reagarding select() Date: Tue, 28 Oct 2008 16:16:07 -0700 From: Bill Cheng Someone wrote: > So i am receiving in an while(1) loop .So i will have call : > FD_ZERO(&fds); > FD_SET(fd, &fds); > before calling every select ? Please don't ask me if this is right. You need to understand what each statement is doing and figure out if it's right for you. -- Bill Cheng // bill.cheng@usc.edu On Tue, Oct 28, 2008 at 2:25 PM, Bill Cheng wrote: > Someone wrote: > > > The syntax for select is > > int select( int nfds,fd_set *read,fd_set *write, fd_set *error,Struct > > timeval *timeout)) > > > > Now , i have multiple readind threads calling select().Each select() scans > > socket descriptors from 0 to nfds-1. > > Will a reading thread 's(with sock fd =5) select() unblock if another > > reading thread (with sock fd = 3) receives data . > > Beacause the former's select will scan from sock fds 0-4. > > You need to use FD_SET() to specify which file descriptors > are you interested in for a specific select() call. For > example, if your thread is only interested in reading fd=5, > then you should do: > > fd_set fds; > struct timeval timeout; > > FD_ZERO(&fds); /* it's imperative that you initialize all variables */ > FD_SET(fd, &fds); > .... /* set timeout */ > return_code = select(fd+1, &fds, NULL, NULL, &timeout); > > Although it will *scan* from file descriptors 0 through 5, it > will skip the ones that you did not call FD_SET() on. > -- > Bill Cheng // bill.cheng@usc.edu