Home > Software engineering >  A great god, about the socket select shortest only 10 ms, overtime can't shrink problem
A great god, about the socket select shortest only 10 ms, overtime can't shrink problem

Time:10-05

TV. Tv_sec=0;
TV. Tv_usec=500;
Ret=select (sockudp + 1, & amp; The FDS, NULL, NULL, & amp; TV);
select timeout has been set to 500 microseconds, why the print information displayed below, a timeout of 10 milliseconds?
this time, what reason be?

Attach part of the code,
 
Void main_loop ()
{
Struct timeval TV, tv2, tv3;
Int ret.
Fd_set FDS.
Int sockudp=create_udp_sock ();
While (1)
{
FD_ZERO (& amp; The FDS);
FD_SET (sockudp, & amp; The FDS);
TV. Tv_sec=0;
TV. Tv_usec=500;
The gettimeofday (& amp; Tv2, NULL);
Ret=select (sockudp + 1, & amp; The FDS, NULL, NULL, & amp; TV);
The gettimeofday (& amp; Tv3, NULL);
Time: printf (" % ld: % ld=========% ld: % ld \ n ", tv2. Tv_sec, tv2. Tv_usec, tv3. Tv_sec, tv3. Tv_usec);
If (ret & gt; 0)
{
ProcessData ();
}
}
The return;
}


Attach a part print information:
Time: 946707221-881299=========946707221:891231
Time: 946707221-891299=========946707221:901227
Time: 946707221-901294=========946707221:911227
Time: 946707221-911293=========946707221:921227
Time: 946707221-921293=========946707221:931227
Time: 946707221-931293=========946707221:941227
Time: 946707221-941291=========946707221:951227
Time: 946707221-951292=========946707221:961227
Time: 946707221-961293=========946707221:971227
Time: 946707221-971292=========946707221:981226
Time: 946707221-981292=========946707221:991227
Time: 946707221-991290=========946707222:1233
Time: 946707222-1311=========946707222:11231
Time: 946707222-11301=========946707222:21227
Time: 946707222-21295=========946707222:31227
Time: 946707222-31292=========946707222:41233
Time: 946707222-41306=========946707222:51229
Time: 946707222-51297=========946707222:61227
Time: 946707222-61293=========946707222:71228
Time: 946707222-71295=========946707222:81227
Time: 946707222-81294=========946707222:91229
Time: 946707222-91298=========946707222:101228
Time: 946707222-101298=========946707222:111228
Time: 946707222-111293=========946707222:121228
Time: 946707222-121294=========946707222:131228
Time: 946707222-131293=========946707222:141227
Time: 946707222-141292=========946707222:151228
Time: 946707222-151292=========946707222:161230
Time: 946707222-161302=========946707222:171228
Time: 946707222-171294=========946707222:181227
Time: 946707222-181292=========946707222:191227
Time: 946707222-191293=========946707222:201234
Time: 946707222-201312=========946707222:211230
Time: 946707222-211302=========946707222:221228
Time: 946707222-221297=========946707222:231228
Time: 946707222-231294=========946707222:241227
Time: 946707222-241292=========946707222:251227
Time: 946707222-251292=========946707222:261227
Time: 946707222-261294=========946707222:271235
Time: 946707222-271309=========946707222:281233
Time: 946707222-281304=========946707222:291229
Time: 946707222-291297=========946707222:301182
Time: 946707222-301225=========946707222:311193
Time: 946707222-311264=========946707222:321176
Time: 946707222-321243=========946707222:331173
Time: 946707222-331222=========946707222:341225
Time: 946707222-341265=========946707222:351227
Time: 946707222-351265=========946707222:361227
Time: 946707222-361264=========946707222:371192
Time: 946707222-371232=========946707222:381197
Time: 946707222-381268=========946707222:391273
Time: 946707222-391323=========946707222:401245
Time: 946707222-401293=========946707222:411231
Time: 946707222-411271=========946707222:421228

CodePudding user response:

http://blog.csdn.net/imhikaru/article/details/7268312

CodePudding user response:

15 ms Windows timing accuracy of material

CodePudding user response:

Thread, through what way can short time waiting for a period of time, again???

CodePudding user response:

 Sleep (0);//wait for a few milliseconds 

"Windows core programming"

CodePudding user response:

I use the
Usleep (1);
Waiting is also 10 ms

CodePudding user response:

I need to wait for 0.5 ms

CodePudding user response:

refer to 6th floor celine_sh response:
I need to wait for 0.5 ms

That would suggest that you use VxWorks

CodePudding user response:

Timeout has some limitations, need set, such as the kernel level or driven development, etc

CodePudding user response:

Operating system limit, accuracy and can't improve.
  • Related