Commit b24cbd48d2168c4c0f5970f926a8d3b3c9ceb53a

Authored by Georg Hopp
1 parent 778b5c4d

timeouts are now in milliseconds

... ... @@ -46,8 +46,8 @@ TR_CLASS(TR_EventDispatcher) {
46 46 TR_Hash handler;
47 47 TR_EventHandler default_handler;
48 48 int running;
49   - time_t heartbeat;
50   - time_t nextbeat;
  49 + int heartbeat; // milliseconds
  50 + int nextbeat; // milliseconds
51 51 TR_EventDispatcherMode mode;
52 52 };
53 53 TR_INSTANCE_INIT(TR_EventDispatcher);
... ... @@ -61,12 +61,12 @@ TR_CLASSVARS_DECL(TR_EventDispatcher) {
61 61 #define TR_DISPATCHER_EVENT_SHUTDOWN 3
62 62 #define TR_DISPATCHER_EVENT_MAX ((size_t)TR_DISPATCHER_EVENT_SHUTDOWN)
63 63
64   -void TR_eventDispatcherRegisterHandler(TR_EventDispatcher, TR_EventHandler);
65   -void TR_eventDispatcherSetHeartbeat(TR_EventDispatcher, time_t);
66   -time_t TR_eventDispatcherGetBeatTime(TR_EventDispatcher);
67   -time_t TR_eventDispatcherGerDataWaitTime(TR_EventDispatcher);
68   -void TR_eventDispatcherStart(TR_EventDispatcher);
69   -void TR_eventDispatcherShutdown(TR_EventDispatcher);
  64 +void TR_eventDispatcherRegisterHandler(TR_EventDispatcher, TR_EventHandler);
  65 +void TR_eventDispatcherSetHeartbeat(TR_EventDispatcher, int);
  66 +int TR_eventDispatcherGetBeatTime(TR_EventDispatcher);
  67 +int TR_eventDispatcherGerDataWaitTime(TR_EventDispatcher);
  68 +void TR_eventDispatcherStart(TR_EventDispatcher);
  69 +void TR_eventDispatcherShutdown(TR_EventDispatcher);
70 70
71 71 #define TR_eventDispatcherEnqueueEvent(disp,ev) \
72 72 (TR_queuePut((disp)->events, (ev)))
... ...
... ... @@ -26,10 +26,16 @@
26 26
27 27 #include "tr/event_dispatcher.h"
28 28
29   -time_t
  29 +int
30 30 TR_eventDispatcherGetBeatTime(TR_EventDispatcher this)
31 31 {
32   - return this->nextbeat - time(NULL);
  32 + struct timespec tp;
  33 + int now; // milliseconds
  34 +
  35 + clock_gettime(CLOCK_REALTIME, &tp);
  36 + now = tp.tv_sec * 1000 + tp.tv_nsec / 1000000;
  37 +
  38 + return this->nextbeat - now;
33 39 }
34 40
35 41 // vim: set ts=4 sw=4:
... ...
... ... @@ -20,13 +20,11 @@
20 20 * along with this program. If not, see <http://www.gnu.org/licenses/>.
21 21 */
22 22
23   -#include <time.h>
24   -
25 23 #include "trbase.h"
26 24
27 25 #include "tr/event_dispatcher.h"
28 26
29   -time_t
  27 +int
30 28 TR_eventDispatcherGetDataWaitTime(TR_EventDispatcher this)
31 29 {
32 30 if (TR_EVD_SERVER == this->mode) {
... ...
... ... @@ -27,12 +27,18 @@
27 27 #include "tr/event_dispatcher.h"
28 28
29 29 void
30   -TR_eventDispatcherSetHeartbeat(TR_EventDispatcher this, time_t heartbeat)
  30 +TR_eventDispatcherSetHeartbeat(TR_EventDispatcher this, int heartbeat)
31 31 {
  32 + struct timespec tp;
  33 + int now; // milliseconds
  34 +
  35 + clock_gettime(CLOCK_REALTIME, &tp);
  36 + now = tp.tv_sec * 1000 + tp.tv_nsec / 1000000;
  37 +
32 38 this->heartbeat = heartbeat;
33 39
34 40 if (this->heartbeat) {
35   - this->nextbeat = time(NULL) + this->heartbeat;
  41 + this->nextbeat = now + this->heartbeat;
36 42 } else {
37 43 this->nextbeat = 0;
38 44 }
... ...
... ... @@ -36,8 +36,12 @@ TR_eventDispatcherStart(TR_EventDispatcher this)
36 36 this->running = 1;
37 37
38 38 while (this->running || (! TR_queueEmpty(this->events))) {
39   - time_t now = time(NULL);
40   - TR_Event current = NULL;
  39 + struct timespec tp;
  40 + int now; // milliseconds
  41 + TR_Event current = NULL;
  42 +
  43 + clock_gettime(CLOCK_REALTIME, &tp);
  44 + now = tp.tv_sec * 1000 + tp.tv_nsec / 1000000;
41 45
42 46 if (this->nextbeat && this->nextbeat <= now) {
43 47 this->nextbeat += this->heartbeat;
... ...
Please register or login to post a comment