Hi Boris,
--- godot <mo...@gm...> wrote:
> While stepping through your select function I noticed: on first call
> "timeout" is set to 1 second, on all following calls the "timeout"
> pointer is 0.
> So,
> 1. your code change does not apply and
> 2. ::select will return immediatly indeed, as you suspected
Actually if the timeout pointer is 0 then select is supposed to block
indefinitely, but in this particular case is returning because the
"socket_select_interrupter" is being made readable.
Unfortunately, stepping through the code doesn't seem to help in
debugging this issue, because long pauses as you step between function
calls change the behaviour of the timer :(
What I did was insert a few printfs into the asio code to see what was
going on with the test program you sent. Can you try the following
changes (i.e. with the earlier change that i suggested disabled) to see
what you get:
Index: select_reactor.hpp
===================================================================
RCS file: /cvsroot/asio/asio/include/asio/detail/select_reactor.hpp,v
retrieving revision 1.37
diff -u -u -r1.37 select_reactor.hpp
--- select_reactor.hpp 2 Feb 2006 07:02:01 -0000 1.37
+++ select_reactor.hpp 28 Feb 2006 10:16:32 -0000
@@ -264,6 +264,7 @@
read_op_queue_.dispatch_cancellations();
write_op_queue_.dispatch_cancellations();
}
+ printf("Dispatching timers\n");
timer_queue_.dispatch_timers(
boost::posix_time::microsec_clock::universal_time());
Index: socket_ops.hpp
===================================================================
RCS file: /cvsroot/asio/asio/include/asio/detail/socket_ops.hpp,v
retrieving revision 1.36
diff -u -u -r1.36 socket_ops.hpp
--- socket_ops.hpp 23 Feb 2006 12:31:08 -0000 1.36
+++ socket_ops.hpp 28 Feb 2006 10:22:54 -0000
@@ -466,8 +466,17 @@
::Sleep(milliseconds);
return 0;
}
+ if (timeout)
+ printf("select timeout = { %d, %d }\n", timeout->tv_sec,
timeout->tv_usec);
+ else
+ printf("select timeout = NULL\n");
+ //if (timeout && timeout->tv_sec == 0
+ // && timeout->tv_usec > 0 && timeout->tv_usec < 10000)
+ // timeout->tv_usec = 10000;
#endif // defined(BOOST_WINDOWS)
- return error_wrapper(::select(nfds, readfds, writefds, exceptfds,
timeout));
+ int r = error_wrapper(::select(nfds, readfds, writefds, exceptfds,
timeout));
+ printf("select result = %d\n", r);
+ return r;
}
You may need to pipe the output to a file so that the printfs don't
change the timing too much. When I run it, sometimes I see things like
the following in the output:
restart
select result = 1
Dispatching timers
select timeout = { 0, 992800 }
select result = 0
Dispatching timers
select timeout = { 0, 1374 }
select result = 0
Dispatching timers
select timeout = { 0, 1374 }
select result = 0
Dispatching timers
select timeout = { 0, 1374 }
select result = 0
Dispatching timers
select timeout = { 0, 1374 }
select result = 0
Dispatching timers
select timeout = NULL
restart
which shows the select call returning immediately in spite of the
timeout value.
Cheers,
Chris
|