/** * add a event * * @see network_connection_pool_lua_add_connection() */ void chassis_event_add_local_with_timeout(chassis G_GNUC_UNUSED *chas, struct event *ev, struct timeval *tv) { struct event_base *event_base = chas->event_base; chassis_event_op_t *op; g_assert(event_base); op = chassis_event_op_new(); op->type = CHASSIS_EVENT_OP_ADD; op->ev = ev; chassis_event_op_set_timeout(op, tv); chassis_event_op_apply(op, event_base); chassis_event_op_free(op); }
/** * add a event to the current thread * * needs event-base stored in the thread local storage * * @see network_connection_pool_lua_add_connection() */ void chassis_event_add_local(chassis G_GNUC_UNUSED *chas, struct event *ev) { struct event_base *event_base = ev->ev_base; chassis_event_op_t *op; if (!event_base) event_base = g_private_get(tls_event_base_key); g_assert(event_base); /* the thread-local event-base has to be initialized */ op = chassis_event_op_new(); op->type = CHASSIS_EVENT_OP_ADD; op->ev = ev; chassis_event_op_apply(op, event_base); chassis_event_op_free(op); }
void chassis_event_add_with_timeout(chassis *chas, struct event *ev, struct timeval *tv) { chassis_event_op_t *op = chassis_event_op_new(); gssize ret; op->type = CHASSIS_EVENT_OP_ADD; op->ev = ev; chassis_event_op_set_timeout(op, tv); g_async_queue_push_unlocked(chas->event_queue, op); g_debug("%s: cal chassis_event_add_with_timeout, fd:%d, timeout sec:%d,usec:%d", G_STRLOC, chas->event_notify_fds[1], (int) tv->tv_sec, (int) tv->tv_usec); /* ping the event handler */ if (1 != (ret = send(chas->event_notify_fds[1], C("."), 0))) { int last_errno; last_errno = errno; g_debug("%s: cal chassis_event_add_with_timeout, fd:%d errno:%d", G_STRLOC, chas->event_notify_fds[1], last_errno); switch (last_errno) { case EAGAIN: case E_NET_WOULDBLOCK: /* that's fine ... */ g_debug("%s: send() to event-notify-pipe failed: %s (len = %d)", G_STRLOC, g_strerror(errno), g_async_queue_length_unlocked(chas->event_queue)); break; default: g_critical("%s: send() to event-notify-pipe failed: %s (len = %d)", G_STRLOC, g_strerror(errno), g_async_queue_length_unlocked(chas->event_queue)); break; } } }