#undef LOCAL_DEBUG
-#include "ucw/lib.h"
-#include "ucw/heap.h"
-#include "ucw/mainloop.h"
-#include "ucw/threads.h"
-#include "ucw/gary.h"
+#include <ucw/lib.h>
+#include <ucw/heap.h>
+#include <ucw/mainloop.h>
+#include <ucw/threads.h>
+#include <ucw/gary.h>
+#include <ucw/process.h>
+#include <ucw/time.h>
#include <stdio.h>
#include <string.h>
static void
main_get_time_ctx(struct main_context *m)
{
- struct timeval tv;
- gettimeofday(&tv, NULL);
- m->now_seconds = tv.tv_sec;
- m->now = (timestamp_t)tv.tv_sec * 1000 + tv.tv_usec / 1000;
+ m->now = get_timestamp();
}
static struct main_context *
return (m == main_current_nocheck());
}
-static inline uns
+static inline uint
count_timers(struct main_context *m)
{
if (m->timer_table)
DBG("MAIN: Setting timer %p (expire at now+%lld)", tm, (long long)(expires - m->now));
else
DBG("MAIN: Clearing timer %p", tm);
- uns num_timers = count_timers(m);
+ uint num_timers = count_timers(m);
if (tm->expires < expires)
{
if (!tm->expires)
{
tm->expires = expires;
tm->index = num_timers + 1;
- *GARY_PUSH(m->timer_table, 1) = tm;
- HEAP_INSERT(struct main_timer *, m->timer_table, tm->index, MAIN_TIMER_LESS, MAIN_TIMER_SWAP);
+ GARY_RESIZE(m->timer_table, num_timers + 2);
+ HEAP_INSERT(struct main_timer *, m->timer_table, num_timers, MAIN_TIMER_LESS, MAIN_TIMER_SWAP, tm);
}
else
{
tm->expires = expires;
- HEAP_INCREASE(struct main_timer *, m->timer_table, num_timers, MAIN_TIMER_LESS, MAIN_TIMER_SWAP, tm->index);
+ HEAP_INCREASE(struct main_timer *, m->timer_table, num_timers, MAIN_TIMER_LESS, MAIN_TIMER_SWAP, tm->index, tm);
}
}
else if (tm->expires > expires)
HEAP_DELETE(struct main_timer *, m->timer_table, num_timers, MAIN_TIMER_LESS, MAIN_TIMER_SWAP, tm->index);
tm->index = 0;
tm->expires = 0;
- GARY_POP(m->timer_table, 1);
+ GARY_POP(m->timer_table);
}
else
{
tm->expires = expires;
- HEAP_DECREASE(struct main_timer *, m->timer_table, num_timers, MAIN_TIMER_LESS, MAIN_TIMER_SWAP, tm->index);
+ HEAP_DECREASE(struct main_timer *, m->timer_table, num_timers, MAIN_TIMER_LESS, MAIN_TIMER_SWAP, tm->index, tm);
}
}
}
timer_add(tm, 0);
}
-static uns
+static uint
file_want_events(struct main_file *fi)
{
- uns events = 0;
+ uint events = 0;
if (fi->read_handler)
events |= POLLIN;
if (fi->write_handler)
#ifdef LOCAL_DEBUG
msg(L_DEBUG | L_SIGHANDLER, "MAIN: Sigpipe: sending signal %d down the drain", signum);
#endif
- write(m->sig_pipe_send, &signum, sizeof(signum));
+ if (write(m->sig_pipe_send, &signum, sizeof(signum)) < 0)
+ {
+ }
}
void
signal_del_ctx(main_current(), ms);
}
-#ifdef CONFIG_DEBUG
+#ifdef CONFIG_UCW_DEBUG
void
file_debug(struct main_file *fi)
{
msg(L_DEBUG, "### Main loop status on %lld", (long long) m->now);
msg(L_DEBUG, "\tActive timers:");
- uns num_timers = count_timers(m);
- for (uns i = 1; i <= num_timers; i++)
+ uint num_timers = count_timers(m);
+ for (uint i = 1; i <= num_timers; i++)
timer_debug(m->timer_table[i]);
msg(L_DEBUG, "\tActive files:");
CLIST_FOR_EACH(struct main_file *, fi, m->file_list)
#else
struct pollfd *p = m->poll_table;
struct main_file **pf = m->poll_file_table;
- for (uns i=0; i < m->file_cnt; i++)
+ for (uint i=0; i < m->file_cnt; i++)
if (p[i].revents)
{
struct main_file *fi = pf[i];