Esempio n. 1
0
static void luv_on_udp_send(uv_udp_send_t* req, int status) {
  luv_udp_ref_t *ref;
  /* load the lua state and the userdata */
  lua_State *L = luv_handle_get_lua(req->handle->data);
  lua_pop(L, 1); /* We don't need the userdata */
  /* load the callback */
  ref =  req->data;
  lua_rawgeti(L, LUA_REGISTRYINDEX, ref->ref);
  luaL_unref(L, LUA_REGISTRYINDEX, ref->ref);
  free(ref);

  if (lua_isfunction(L, -1)) {
    if (status != 0) {
      luv_push_async_error(L, uv_last_error(luv_get_loop(L)), "on_udp_send", NULL);
      luv_acall(L, 1, 0, "on_udp_send");
    } else {
      luv_acall(L, 0, 0, "on_udp_send");
    }
  } else {
    lua_pop(L, 1);
  }

  luv_handle_unref(L, req->handle->data);
  free(req);
}
Esempio n. 2
0
int luv_udp_recv_stop(lua_State* L) {
  uv_udp_t* handle = (uv_udp_t*)luv_checkudata(L, 1, "udp");
  if (uv_udp_recv_stop(handle)) {
    uv_err_t err = uv_last_error(luv_get_loop(L));
    return luaL_error(L, "udp_recv_stop: %s", uv_strerror(err));
  }
  luv_handle_unref(L, handle->data);
  return 0;
}
Esempio n. 3
0
int luv_timer_stop(lua_State* L) {
    uv_timer_t* handle = (uv_timer_t*)luv_checkudata(L, 1, "timer");

    int err = uv_timer_stop(handle);
    if (err < 0) {
        return luaL_error(L, "timer_stop: %s", uv_strerror(err));
    }
    luv_handle_unref(L, handle->data);

    return 0;
}
Esempio n. 4
0
void luv_on_close(uv_handle_t* handle) {
    /*  printf("on_close\tlhandle=%p handle=%p\n", handle->data, handle);*/
    /* load the lua state and the userdata */
    luv_handle_t* lhandle = handle->data;
    lua_State *L = lhandle->L;
    lua_rawgeti(L, LUA_REGISTRYINDEX, lhandle->ref);

    luv_emit_event(L, "close", 0);

    luv_handle_unref(L, handle->data);

    if (lhandle->ref != LUA_NOREF) {
        assert(lhandle->refCount);
        /*    fprintf(stderr, "WARNING: closed %s with %d extra refs lhandle=%p handle=%p\n", lhandle->type, lhandle->refCount, handle->data, handle);*/
        lhandle->refCount = 1;
        luv_handle_unref(L, handle->data);
    }
    assert(lhandle->ref == LUA_NOREF);
    /* This handle is no longer valid, clean up memory */
    lhandle->handle = 0;
    free(handle);
}