Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id ; Wed, 25 Jul 2001 09:15:09 -0400 Received: (majordomo@vger.kernel.org) by vger.kernel.org id ; Wed, 25 Jul 2001 09:14:59 -0400 Received: from mx1.nameplanet.com ([62.70.3.31]:54797 "HELO mx1.nameplanet.com") by vger.kernel.org with SMTP id ; Wed, 25 Jul 2001 09:14:48 -0400 Date: Wed, 25 Jul 2001 15:53:34 +0200 (CEST) From: Ketil Froyn To: "M. Tavasti" cc: Subject: Re: Select with device and stdin not working In-Reply-To: Message-ID: MIME-Version: 1.0 Content-Type: TEXT/PLAIN; charset=US-ASCII Sender: linux-kernel-owner@vger.kernel.org X-Mailing-List: linux-kernel@vger.kernel.org Original-Recipient: rfc822;linux-kernel-outgoing On 25 Jul 2001, M. Tavasti wrote: > Here program where I get problems: > > int fd; > fd_set rfds; > > fd = open("/dev/random", O_RDWR ); > > while(1) { > FD_ZERO(&rfds); > FD_SET(fd,&rfds); > FD_SET(fileno(stdin),&rfds); > if( select(fd+1, &rfds, NULL, NULL, NULL ) > 0) { > fprintf(stderr,"Select\n"); > fflush(stderr); > if(FD_ISSET(fd,&rfds)) { > ....... > } else if(FD_ISSET(fileno(stdin),&rfds) ) { > ...... > } > } > } It looks like you are sending the original fd_set to select. Remember that it is modified in place. What is probably happening is that select returns at once when it gets something from /dev/random, and rfds is now modified to only contain this. The next time select runs, it will only be checking for input from /dev/random. You have to make a copy of rfds that is set every time, and send that instead. Ketil - To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html Please read the FAQ at http://www.tux.org/lkml/