Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Event poll timeout is setting to closest timer's time of execution

  • Loading branch information...
commit 0773323089b94721741c05a98800e7c3432a5b4f 1 parent 042739e
@harmer harmer authored paraboul committed
Showing with 15 additions and 2 deletions.
  1. +2 −2 src/sock.c
  2. +12 −0 src/ticks.c
  3. +1 −0  src/ticks.h
View
4 src/sock.c
@@ -294,9 +294,9 @@ unsigned int sockroutine(acetables *g_ape)
#endif
gettimeofday(&t_start, NULL);
while (server_is_running) {
- // int timeout_to_hang = MAX((1000/TICKS_RATE)-ticks, 1);
/* Linux 2.6.25 provides a fd-driven timer system. It could be usefull to implement */
- nfds = events_poll(g_ape->events, 1);
+ int timeout_to_hang = get_first_timer_ms (g_ape);
+ nfds = events_poll(g_ape->events, timeout_to_hang);
if (nfds < 0) {
ape_log(APE_ERR, __FILE__, __LINE__, g_ape,
View
12 src/ticks.c
@@ -143,3 +143,15 @@ void del_timer_identifier(unsigned int identifier, acetables *g_ape)
}
}
+/* Returns closest timer execution time (in ms) */
+int get_first_timer_ms (acetables *g_ape)
+{
+ struct _ticks_callback *timers = g_ape->timers.timers;
+
+ if (timers != NULL) {
+ return timers->delta;
+ }
+
+ return -1;
+}
+
View
1  src/ticks.h
@@ -45,6 +45,7 @@ struct _ticks_callback *add_timeout(unsigned int msec, void *callback, void *par
struct _ticks_callback *add_periodical(unsigned int msec, int times, void *callback, void *params, acetables *g_ape);
void del_timer_identifier(unsigned int identifier, acetables *g_ape);
struct _ticks_callback *get_timer_identifier(unsigned int identifier, acetables *g_ape);
+int get_first_timer_ms (acetables *g_ape);
#define add_ticked(x, y) add_periodical(VTICKS_RATE, 0, x, y, g_ape)
Please sign in to comment.
Something went wrong with that request. Please try again.