LinuxQuestions.org
Support LQ: Use code LQ3 and save $3 on Domain Registration
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices

Reply
 
LinkBack Search this Thread
Old 07-22-2010, 01:56 AM   #1
archieval
Member
 
Registered: Apr 2007
Location: Philippines
Distribution: Kubuntu, Ubuntu, CentOS
Posts: 282

Rep: Reputation: 41
Question In C, select() call does not wait


Hello everyone I have this program,
Code:
	int fd;
	fd_set rd_set;
        struct timeval to;
        char data[128];

        to.tv_sec = 5;
        to.tv_usec = 50;

        fd = open("/dev/misc/gpio", O_RDWR);

        while (1)
        {
            FD_ZERO(&rd_set);
            FD_SET(fd, &rd_set);

            s32ret = select(fd+1, &rd_set, NULL, NULL, &to);
            if (s32ret < 0)
            {
                printf("select() error\n");
		break;
            }
            else if (s32ret == 0)
            {
		printf("select() timeout\n");
                continue;
            }
            else
            {
                if (FD_ISSET(fd, &rd_set))
                {
	            /* do my stuff */
		}
	    }
        }
My problem is after the first 5 seconds of waiting, the timeout values does not take effect anymore on the select() call. There will be a tight loop on the else-if part. Sometimes the select() is successful but on other times it returns zero without even waiting. What could be the problem here?

Last edited by archieval; 07-22-2010 at 02:04 AM. Reason: fixed tabs
 
Old 07-22-2010, 02:57 AM   #2
jf.argentino
Member
 
Registered: Apr 2008
Location: Toulon (France)
Distribution: FEDORA CORE
Posts: 489

Rep: Reputation: 49
If you're under linux, "select" modify the timeout struct... And it's said in the manual (man select)
 
Old 07-22-2010, 03:32 AM   #3
archieval
Member
 
Registered: Apr 2007
Location: Philippines
Distribution: Kubuntu, Ubuntu, CentOS
Posts: 282

Original Poster
Rep: Reputation: 41
Yes in Linux. I didn't noticed that in the manpage. So timeout is undefined after a select() call. Thanks!
 
Old 07-22-2010, 05:28 AM   #4
jf.argentino
Member
 
Registered: Apr 2008
Location: Toulon (France)
Distribution: FEDORA CORE
Posts: 489

Rep: Reputation: 49
Quote:
So timeout is undefined after a select() call
If I well remember it contains the remaining time, so 0 if timeout has expired, and "timeout - (T1 - T0)" where T0 is the date when you call "select", T1 the date when you get out of "select"
 
  


Reply

Tags
select


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Select() call consumes CPU barunparichha Linux - Software 1 03-31-2010 07:14 AM
return value of select() call sinu_nayak2001 Programming 9 10-09-2009 05:33 AM
question about select sys call xatzipol Programming 1 10-30-2005 09:22 AM
C sockets Select call when to use? cranium2004 Programming 1 03-14-2005 05:56 AM
tracing the error code returned by wait call lg3 Linux - Software 0 02-21-2005 03:53 AM


All times are GMT -5. The time now is 03:40 PM.

Main Menu
 
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: @linuxquestions
Open Source Consulting | Domain Registration