Free Downloads, Community Forum,
FAQs and Developer Resources


Make /Tools Your Home | Link to us

Today's posts | Posts since last visit | Most Active Topics

All Forums Register Login Search Subscriptions My Profile Inbox
Tool Warehouse FAQs Resources Help Member List Address Book Logout

select(2) ignoring timeval argument

 
Logged in as: Guest
Users viewing this topic: none
  Printable Version
All Forums >> [SFU / Interix / SUA Technology] >> Windows Server 2003 R2 SUA >> select(2) ignoring timeval argument Page: [1]
Login
Message << Older Topic   Newer Topic >>
select(2) ignoring timeval argument - Mar. 11, '06, 9:37:02 PM   
breiter

 

Posts: 343
Joined: Jun. 14, '04,
From: Washington, DC
Status: offline
When I upgraded to SUA/Interix 5.2, I installed xgalaga. Which is frivolous, I know. The thing is that it works fine on SFU/Interix 3.5 but runs crazy-fast on SUA/Interix 5.2. The entire thing is a blur.

I pinged Rodney on this and he mentioned that xgalaga uses select(2) to throttle its speed. Thinking maybe I just needed to change the timing, I downloaded grabbed the xgalaga source code. Building it myself didn't help. I looked at documentation of select(2).

From man 2 select:

If timeout is a non-nil pointer, it specifies a maximum interval to wait
for the selection to complete. If timeout is a nil pointer, the select
blocks indefinitely. To effect a poll, the timeout argument should be non-
nil, pointing to a zero-valued timeval structure.

I injected this code at the end of the while(1) loop.

//insert a 10 second pause on every loop to test select().
struct timeval pause;
gettimeofday(&pause, 0);
printf("Get pause time: %d\n", pause.tv_sec);
pause.tv_sec += 10L;
printf("Add 10 seconds: %d\n", pause.tv_sec);
(void) select(0, 0, 0, 0, &pause);

This is the kind of output I get while xgalaga is running.

Get pause time: 1142130333
Add 10 seconds: 1142130343
Get pause time: 1142130333
Add 10 seconds: 1142130343
Get pause time: 1142130333
Add 10 seconds: 1142130343
Get pause time: 1142130333
Add 10 seconds: 1142130343
Get pause time: 1142130333
Add 10 seconds: 1142130343
Get pause time: 1142130333
Add 10 seconds: 1142130343
Get pause time: 1142130333
Add 10 seconds: 1142130343
Get pause time: 1142130333
Add 10 seconds: 1142130343
Get pause time: 1142130333
Add 10 seconds: 1142130343
Get pause time: 1142130333
Add 10 seconds: 1142130343

No pause happened when select was called, so we're on the same second when the next loop iteration comes around. I think there is something very wrong here. Select(2) seems to be ignoring the timeval pause.
Post #: 1
RE: select(2) ignoring timeval argument - Mar. 12, '06, 2:57:57 PM   
Rodney

 

Posts: 3695
Joined: Jul. 9, '02,
From: /Tools lab
Status: online
mmmm, we're starting to build up quite a selection of things with SUA.
1) Select timer ignored (mentioned above)
2) The SetUid problem (mentioned by Brian in another thread)
3) The AF_UNIX sockets have had the namespace shrunk from 104 to 14 characters.

(in reply to breiter)
Post #: 2
RE: select(2) ignoring timeval argument - Mar. 15, '06, 10:00:57 AM   
breiter

 

Posts: 343
Joined: Jun. 14, '04,
From: Washington, DC
Status: offline
Here's a very simple test program that demonstrates the select(2) timeout problem in isolation:

#include <stdio.h>
#include <sys/time.h>

int main()
{
        printf("Testing select(2). Each pass through the loop should pause 10 seconds.\n\n");

        struct timeval time, pause;
        pause.tv_sec  = 10;
        pause.tv_usec = 0;
        int i;

        for( i=0; i<10; i++ )
        {
                //insert a 10 second pause on every loop to test select().              
                gettimeofday(&time, 0);
                printf("Current time: %d\n", time.tv_sec);
                time.tv_sec += 10L;
                printf("Add 10 seconds: %d... And pause by calling select(2).\n", time.tv_sec);
                (void) select(0, 0, 0, 0, &pause);
        }
        return 0;
}


% gcc selecttest.c -o selecttest
% ./selecttest
Testing select(2). Each pass through the loop should pause 10 seconds.

Current time: 1142434664
Add 10 seconds: 1142434674... And pause by calling select(2).
Current time: 1142434664
Add 10 seconds: 1142434674... And pause by calling select(2).
Current time: 1142434664
Add 10 seconds: 1142434674... And pause by calling select(2).
Current time: 1142434664
Add 10 seconds: 1142434674... And pause by calling select(2).
Current time: 1142434664
Add 10 seconds: 1142434674... And pause by calling select(2).
Current time: 1142434664
Add 10 seconds: 1142434674... And pause by calling select(2).
Current time: 1142434664
Add 10 seconds: 1142434674... And pause by calling select(2).
Current time: 1142434664
Add 10 seconds: 1142434674... And pause by calling select(2).
Current time: 1142434664
Add 10 seconds: 1142434674... And pause by calling select(2).
Current time: 1142434664
Add 10 seconds: 1142434674... And pause by calling select(2).

< Message edited by breiter -- Mar. 20, '06, 1:12:57 PM >

(in reply to Rodney)
Post #: 3
RE: select(2) ignoring timeval argument - Apr. 3, '06, 3:22:03 PM   
breiter

 

Posts: 343
Joined: Jun. 14, '04,
From: Washington, DC
Status: offline
I've heard back from the product team. They know about the issue, but it isn't currently eligible for a hotfix because a workaround exists. The fix is currently scheduled for the next "version" of Interix, which mean Windows Vista and/or Window Server 2003 (R2) SP2.

In the mean time, the recommended workaround is to use sleep(3)/usleep(3) to block instead of the timeval option in select(2).

quote:

This is a known issue with Windows 2003 R2 and is already planned to be fixed in the next update release for the product in the form of a fix or a product upgrade. However as a workaround you might try to use sleep or usleep. This is a recommended workaround for this issue.


I'm not sure how well that workaround is going to work with socket polling, but it does work for my lame example issue with xgalaga which was just using select(2) to pause the main program loop.
% diff -u main-ori.c main.c
--- main-ori.c  Mon May 11 02:52:59 1998
+++ main.c      Mon Apr  3 15:12:50 2006
@@ -1152,11 +1152,13 @@
             tv.tv_usec += (tv.tv_sec - otv.tv_sec) * 1000000;
         ut = tv.tv_usec - otv.tv_usec;
         if(UTIMER - ut > 0) {
-            struct timeval tv;
+           // struct timeval tv;
             unsigned long usecs = UTIMER - ut;
-            tv.tv_sec  = usecs / 1000000L;
-            tv.tv_usec = usecs % 1000000L;
-            (void) select (0, 0, 0, 0, &tv);
+           // tv.tv_sec  = usecs / 1000000L;
+           // tv.tv_usec = usecs % 1000000L;
+           // (void) select (0, 0, 0, 0, &tv);
+            sleep( usecs / 1000000L );
+            usleep( usecs % 1000000L );
        }

         gettimeofday(&otv, 0);

(in reply to breiter)
Post #: 4
Page:   [1]
All Forums >> [SFU / Interix / SUA Technology] >> Windows Server 2003 R2 SUA >> select(2) ignoring timeval argument Page: [1]
Jump to:





New Messages No New Messages
Hot Topic w/ New Messages Hot Topic w/o New Messages
Locked w/ New Messages Locked w/o New Messages
 Post New Thread
 Reply to Message
 Post New Poll
 Submit Vote
 Delete My Own Post
 Delete My Own Thread
 Rate Posts


Search All Forums -

Advanced search


SPONSORS



Forum Software © ASPPlayground.NET Advanced Edition 2.5 ANSI

0.031