Return-Path: william@bourbon.usc.edu Delivery-Date: Tue Oct 28 14:14:23 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 m9SLENdM008851 for ; Tue, 28 Oct 2008 14:14:23 -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 m9SLPUFF002686 for ; Tue, 28 Oct 2008 14:25:30 -0700 Message-Id: <200810282125.m9SLPUFF002686@bourbon.usc.edu> To: cs551@merlot.usc.edu Subject: Re: reagarding select() Date: Tue, 28 Oct 2008 14:25:30 -0700 From: Bill Cheng 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