예제 #1
0
/**
 * Starts the idle so it won't be called by the specified event loop.
 *
 * Usage:
 *     idle:start(loop [, is_daemon])
 *
 * [+0, -0, e]
 */
static int idle_start(lua_State *L) {
    ev_idle*        idle   = check_idle(L, 1);
    struct ev_loop* loop   = *check_loop_and_init(L, 2);
    int is_daemon          = lua_toboolean(L, 3);

    ev_idle_start(loop, idle);
    loop_start_watcher(L, 2, 1, is_daemon);

    return 0;
}
예제 #2
0
/**
 * Starts the timer so it won't be called by the specified event loop.
 *
 * Usage:
 *     timer:start(loop [, is_daemon])
 *
 * [+0, -0, e]
 */
static int timer_start(lua_State *L) {
    ev_timer*       timer  = check_timer(L, 1);
    struct ev_loop* loop   = *check_loop_and_init(L, 2);
    int is_daemon          = lua_toboolean(L, 3);

    ev_timer_start(loop, timer);
    loop_start_watcher(L, 2, 1, is_daemon);

    return 0;
}
예제 #3
0
/**
 * Starts the child so it will be called by the specified event loop.
 *
 * Usage:
 *     child:start(loop [, is_daemon])
 *
 * [+0, -0, e]
 */
static int child_start(lua_State *L) {
    ev_child*       child = check_child(L, 1);
    struct ev_loop* loop = *check_loop_and_init(L, 2);
    int is_daemon        = lua_toboolean(L, 3);

    ev_child_start(loop, child);
    loop_start_watcher(L, loop, GET_WATCHER_DATA(child), 2, 1, is_daemon);

    return 0;
}
예제 #4
0
/**
 * Restart a timer with the specified repeat number of seconds.  If no
 * repeat was specified, the timer is simply stopped.  May optionally
 * specify a new value for repeat, otherwise uses the value set when
 * the timer was created.
 *
 *   1 - timer object.
 *   2 - loop object.
 *   3 - repeat (number of seconds to wait for consecutive timeouts).
 *
 * Usage:
 *    timer:again(loop [, repeat_seconds])
 *
 * [+0, -0, e]
 */
static int timer_again(lua_State *L) {
    ev_timer*       timer     = check_timer(L, 1);
    struct ev_loop* loop      = *check_loop_and_init(L, 2);
    ev_tstamp       repeat    = luaL_optnumber(L, 3, 0);

    if ( repeat < 0.0 ) luaL_argerror(L, 3, "repeat must be greater than 0");

    if ( repeat ) timer->repeat = repeat;

    if ( timer->repeat ) {
        ev_timer_again(loop, timer);
        loop_start_watcher(L, 2, 1, -1);
    } else {
        /* Just calling stop instead of again in case the symantics
         * change in libev */
        loop_stop_watcher(L, 2, 1);
        ev_timer_stop(loop, timer);
    }

    return 0;
}