void calldonecb(struct aura_node *dev, int status, struct aura_buffer *retbuf, void *arg) { printf("Call done with result %d arg %lld!\n", status, (long long unsigned int) arg); if (arg != (void *) ARG) exit(1); aura_hexdump("Out buffer", retbuf->data, retbuf->size); aura_eventloop_loopexit(aura_node_eventloop_get(dev), NULL); }
void pingcb(struct aura_node *dev, int status, struct aura_buffer *retbuf, void *arg) { numevt++; printf("Event number %d with result %d arg %lld!\n", numevt, status, (long long unsigned int) arg); if (arg != (void *) ARG2) exit(1); aura_hexdump("Out buffer", retbuf->data, retbuf->size); if (numevt==4) { printf("Breaking the loop\n"); aura_eventloop_loopexit(aura_node_eventloop_get(dev), NULL); } }
/*** Terminate the event processing loop (Internal). Do not call this functuion directly. @see eventloop.loopexit The timeout is given in seconds, fractions of seconds are welcome. Zero timeout or omitting the second argument will cause immediate eventloop termination. ProTIP: You can call this function BEFORE aura.eventloop_dispatch() @function aura.eventloop_loopexit @param loop [loop] eventloop instance @param timeout [number, optional] if specified, the eventloop will be terminated after timeout number of seconds. If no timeout given - the eventloop will be stop immediately. */ static int l_eventloop_loopexit(lua_State *L) { TRACE(); struct laura_eventloop *lloop; aura_check_args(L, 1); struct timeval tv; if (!lua_isuserdata(L, 1)) aura_typeerror(L, 1, "ludata"); lloop = lua_touserdata(L, 1); if (lua_isnumber(L,2)) { lua_totimeout(L, 2, &tv); } else { tv.tv_sec = 0; tv.tv_usec = 0; } aura_eventloop_loopexit(lloop->loop, &tv); return 0; }
/*** Terminate the event processing loop (Internal). Do not call this functuion directly. @see eventloop.loopexit The timeout is given in seconds, fractions of seconds are welcome. Zero timeout or omitting the second argument will cause immediate eventloop termination. ProTIP: You can call this function BEFORE aura.eventloop_dispatch() @function aura.eventloop_loopexit @param loop [loop] eventloop instance @param timeout [number, optional] if specified, the eventloop will be terminated after timeout number of seconds. If no timeout given - the eventloop will be stop immediately. */ static int l_eventloop_loopexit(lua_State *L) { TRACE(); struct laura_eventloop *lloop; double timeout; aura_check_args(L, 1); struct timeval tv; if (!lua_isuserdata(L, 1)) aura_typeerror(L, 1, "ludata"); lloop = lua_touserdata(L, 1); if (lua_gettop(L) == 2) { timeout = lua_tonumber(L, 2); tv.tv_sec = floor(timeout); tv.tv_usec = (timeout - tv.tv_sec) * 1000000; } else { tv.tv_sec = 0; tv.tv_usec = 0; } aura_eventloop_loopexit(lloop->loop, &tv); return 0; }