static void lluv_on_process_exit(uv_process_t* arg, int64_t exit_status, int term_signal){ lluv_handle_t *handle = lluv_handle_byptr((uv_handle_t*)arg); lua_State *L = LLUV_HCALLBACK_L(handle); LLUV_CHECK_LOOP_CB_INVARIANT(L); if(!IS_(handle, OPEN)){ lluv_handle_unlock(L, handle, LLUV_LOCK_EXIT); LLUV_CHECK_LOOP_CB_INVARIANT(L); return; } lua_rawgeti(L, LLUV_LUA_REGISTRY, LLUV_EXIT_CB(handle)); lluv_handle_pushself(L, handle); lluv_handle_unlock(L, handle, LLUV_LOCK_EXIT); if(lua_isnil(L, -2)){ lua_pop(L, 2); LLUV_CHECK_LOOP_CB_INVARIANT(L); return; } lua_pushnil(L); lutil_pushint64(L, exit_status); lutil_pushint64(L, term_signal); LLUV_HANDLE_CALL_CB(L, handle, 4); LLUV_CHECK_LOOP_CB_INVARIANT(L); }
LLUV_INTERNAL void lluv_req_free(lua_State *L, lluv_req_t *req){ luaL_unref(L, LLUV_LUA_REGISTRY, req->cb); luaL_unref(L, LLUV_LUA_REGISTRY, req->arg); luaL_unref(L, LLUV_LUA_REGISTRY, req->ctx); if(req->handle){ lluv_handle_unlock(L, req->handle, LLUV_LOCK_REQ); } lluv_free(L, req); }
static int lluv_poll_stop(lua_State *L){ lluv_handle_t *handle = lluv_check_poll(L, 1, LLUV_FLAG_OPEN); int err = uv_poll_stop(LLUV_H(handle, uv_poll_t)); if(err < 0){ return lluv_fail(L, handle->flags, LLUV_ERR_UV, err, NULL); } lluv_handle_unlock(L, handle, LLUV_LOCK_START); lua_settop(L, 1); return 1; }
static void lluv_on_udp_recv_cb(uv_udp_t *arg, ssize_t nread, const uv_buf_t* buf, const struct sockaddr* addr, unsigned flags){ lluv_handle_t *handle = lluv_handle_byptr((uv_handle_t*)arg); lua_State *L = LLUV_HCALLBACK_L(handle); LLUV_CHECK_LOOP_CB_INVARIANT(L); if((nread == 0) && (addr == NULL)){ /* ** The receive callback will be called with ** nread == 0 and addr == NULL when there is ** nothing to read */ lluv_free_buffer((uv_handle_t*)arg, buf); return; } lua_rawgeti(L, LLUV_LUA_REGISTRY, LLUV_READ_CB(handle)); assert(!lua_isnil(L, -1)); lluv_handle_pushself(L, handle); if(nread >= 0){ assert(addr); lua_pushnil(L); lua_pushlstring(L, buf->base, nread); lluv_free_buffer((uv_handle_t*)arg, buf); } else{ lluv_free_buffer((uv_handle_t*)arg, buf); /* The callee is responsible for stopping closing the stream * when an error happens by calling uv_read_stop() or uv_close(). * Trying to read from the stream again is undefined. */ uv_udp_recv_stop(arg); luaL_unref(L, LLUV_LUA_REGISTRY, LLUV_READ_CB(handle)); LLUV_READ_CB(handle) = LUA_NOREF; lluv_error_create(L, LLUV_ERR_UV, (uv_errno_t)nread, NULL); lua_pushnil(L); lluv_handle_unlock(L, handle, LLUV_LOCK_READ); } lua_pushinteger(L, flags); LLUV_HANDLE_CALL_CB(L, handle, 4 + lluv_push_addr(L, (const struct sockaddr_storage*)addr)); LLUV_CHECK_LOOP_CB_INVARIANT(L); }
static int lluv_udp_stop_recv(lua_State *L){ lluv_handle_t *handle = lluv_check_udp(L, 1, LLUV_FLAG_OPEN); int err; lluv_check_none(L, 2); err = uv_udp_recv_stop(LLUV_H(handle, uv_udp_t)); if(err < 0){ return lluv_fail(L, handle->flags, LLUV_ERR_UV, err, NULL); } if(LLUV_READ_CB(handle) != LUA_NOREF){ luaL_unref(L, LLUV_LUA_REGISTRY, LLUV_READ_CB(handle)); LLUV_READ_CB(handle) = LUA_NOREF; lluv_handle_unlock(L, handle, LLUV_LOCK_READ); } lua_settop(L, 1); return 1; }