Board index » Visual Studio » select function call
|
rstoeck
|
select function call
Visual Studio365
Hi, I have some problem with the select function call. I am trying to execute the select loop for a time out period of 10 msec and it always returns after 11 milli sec. If I execute in a loop for 30 times more than 20 times it returns after 11 milli sec and less than 10 times it returns after 10 mill secs. I took an average for 1000 times and it came out to be 10.886... What should I do to make the select funtion return after exactly 10milli sec. Here is the code. timeBeginPeriod(1); //timeEndPeriod(1); fd = socket(AF_INET,SOCK_DGRAM,0); long int diff =0, before = 0, after = 0; timeval t; int result=-1; int test = 1; long duration = 0x0; timeb timeStart, timeEnd; float average = 0; //while (1) for (int i=0; i<loops; i++) { diff = 0; fds = 0; result=-1; t.tv_sec = 0; t.tv_usec = interval; //t.tv_nsec = interval; FD_ZERO(&excp); FD_SET(fd,&excp); fds++; ftime(&timeStart); before = timeGetTime(); result = select(fds,0x0,0x0,&excp,&t); //Sleep(10); result=0; after = timeGetTime(); diff = after - before; ftime(&timeEnd); average += diff; average /= 2; if ( result == -1 ) cout << WSAGetLastError() << endl; else if (result == 0 && flag) { printf("ftime Timeout occured : %d\n", timeEnd.time - timeStart.time); printf("ftime Timeout occured : %d\n", timeEnd.millitm - timeStart.millitm); printf("MultiMedia Timeout occured : %d\n", diff); } } printf("average MultiMedia Timeout occured : %f\n", average); - |
