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); }
static void lluv_on_getnameinfo(uv_getnameinfo_t* arg, int status, const char* hostname, const char* service){ lluv_req_t *req = lluv_req_byptr((uv_req_t*)arg); lluv_loop_t *loop = lluv_loop_byptr(arg->loop); lua_State *L = loop->L; LLUV_CHECK_LOOP_CB_INVARIANT(L); if(!IS_(loop, OPEN)){ lluv_req_free(L, req); return; } lua_rawgeti(L, LLUV_LUA_REGISTRY, req->cb); lluv_req_free(L, req); assert(!lua_isnil(L, -1)); lluv_loop_pushself(L, loop); lluv_push_status(L, status); if(hostname)lua_pushstring(L, hostname); else lua_pushnil(L); if(service) lua_pushstring(L, service); else lua_pushnil(L); LLUV_LOOP_CALL_CB(L, loop, 4); LLUV_CHECK_LOOP_CB_INVARIANT(L); }
static int lluv_file_close(lua_State *L){ lluv_file_t *f = lluv_check_file(L, 1, 0); lluv_loop_t *loop = f->loop; if(IS_(f, OPEN)){ const char *path = NULL; int argc = 1; UNSET_(f, OPEN); if(!IS_(f, NOCLOSE)){ LLUV_PRE_FILE(); err = uv_fs_close(loop->handle, &req->req, f->handle, cb); LLUV_POST_FILE(); } } return 0; }
static lluv_file_t *lluv_check_file(lua_State *L, int i, lluv_flags_t flags){ lluv_file_t *f = (lluv_file_t *)lutil_checkudatap (L, i, LLUV_FILE); luaL_argcheck (L, f != NULL, i, LLUV_FILE_NAME" expected"); /* loop could be closed already */ if(!IS_(f->loop, OPEN)){ if(IS_(f,OPEN)){ lluv_fs_request_t *req = lluv_fs_request_new(L); UNSET_(f,OPEN); uv_fs_close(NULL, &req->req, f->handle, NULL); lluv_fs_request_free(L, req); } } luaL_argcheck (L, FLAGS_IS_SET(f->flags, flags), i, LLUV_FILE_NAME" closed"); return f; }
static int lluv_file_pipe(lua_State *L){ lluv_file_t *f = lluv_check_file(L, 1, LLUV_FLAG_OPEN); int ipc = lua_toboolean(L, 2); /*local ok, err = uv.pipe(loop, ipc)*/ lua_pushvalue(L, LLUV_LUA_REGISTRY); lua_pushvalue(L, LLUV_LUA_HANDLES); lua_pushcclosure(L, IS_(f, RAISE_ERROR) ? lluv_pipe_create_unsafe : lluv_pipe_create_safe, 2); lluv_loop_pushself(L, f->loop); lua_pushboolean(L, ipc); lua_call(L, 2, 2); /*if not ok then return nil, err*/ if(lua_isnil(L, -2)) return 2; lua_pop(L, 1); /*local ok, err = pipe:open(fd)*/ lua_getfield(L, -1, "open"); assert(lua_isfunction(L, -1)); lua_pushvalue(L, -2); lutil_pushint64(L, f->handle); lua_call(L, 2, 2); /*if not ok then pipe:close() return nil, err*/ if(lua_isnil(L, -2)){ int top = lua_gettop(L); lua_getfield(L, -3, "close"); assert(lua_isfunction(L, -1)); lua_pushvalue(L, -4); lua_pcall(L, 0, 0, 0); lua_settop(L, top); return 2; } lua_pop(L, 2); UNSET_(f, OPEN); return 1; }