static void callback(struct timer_list* timer, void *data) { int res; lua_State *L = (lua_State *)data; lua_pushtimer(L, timer); if (!lua_istable(L, -1)) { syslog(LOG_ERR, "CRON: system error: unable to get cron timer\n"); return; } unregister_timer(L, timer); lua_pushstring(L, "callback"); lua_gettable(L, -2); luaL_checktype(L, -1, LUA_TFUNCTION); lua_pushvalue(L, -2); res = lua_pcall(L, 1, 0, 0); if (res) { char const *name = "?"; char const *err = luaL_checkstring(L, -1); lua_pushstring(L, "name"); lua_gettable(L, -2); if (!lua_isnil(L, -1)) name = lua_tostring(L, -1); syslog(LOG_NOTICE, "CRON: timer [%s] callback error: %s\n", name, err); lua_pop(L, 2); } lua_poptimer(L); }
static int l_reset_timer(lua_State *L) { struct timer_list* timer = lua_checktimer(L, 1); del_timer(timer); unregister_timer(L, timer); return 0; }
void connection_destroy(void *arg) { struct connection *c = (struct connection*)arg; unregister_timer(con2wheelitem(c)); wpacket_t w; while((w = LLIST_POP(wpacket_t,&c->send_list))!=NULL) wpk_destroy(&w); buffer_release(&c->unpack_buf); buffer_release(&c->next_recv_buf); free(c); //printf("connection_destroy\n"); }
static void on_packet(connection *c,packet *p,int32_t error){ if(p){ //rpacket *rpk = (rpacket*)p; //uint64_t id = rpacket_peek_uint64(rpk); //printf("%lld\n",id); //if(id == (uint64_t)c){ // packet_count++; // connection_send(c,make_writepacket(p),NULL); //} }else{ //error or peer close unregister_timer((timer*)c->ud_ptr); connection_close(c); } }
/* #<pydoc> def unregister_timer(timer_obj): """ Unregister a timer @param timer_obj: a timer object previously returned by a register_timer() @return: Boolean @note: After the timer has been deleted, the timer_obj will become invalid. """ pass #</pydoc> */ static PyObject *py_unregister_timer(PyObject *py_timerctx) { PYW_GIL_CHECK_LOCKED_SCOPE(); if ( py_timerctx == NULL || !PyCObject_Check(py_timerctx) ) Py_RETURN_FALSE; py_timer_ctx_t *ctx = (py_timer_ctx_t *) PyCObject_AsVoidPtr(py_timerctx); if ( !unregister_timer(ctx->timer_id) ) Py_RETURN_FALSE; Py_DECREF(ctx->pycallback); delete ctx; Py_RETURN_TRUE; }