Beispiel #1
0
static int lluv_poll_start(lua_State *L){
  static const lluv_uv_const_t FLAGS[] = {
    { UV_READABLE,   "readable"   },
    { UV_WRITABLE,   "writable"   },
#if LLUV_UV_VER_GE(1,9,0)
    { UV_DISCONNECT, "disconnect" },
#endif

    { 0, NULL }
  };

  lluv_handle_t *handle = lluv_check_poll(L, 1, LLUV_FLAG_OPEN);
  int events = UV_READABLE;
  int err;

  if(!lua_isfunction(L, 2))
    events = lluv_opt_flags_ui(L, 2, UV_READABLE, FLAGS);

  lluv_check_args_with_cb(L, 3);
  LLUV_START_CB(handle) = luaL_ref(L, LLUV_LUA_REGISTRY);

  err = uv_poll_start(LLUV_H(handle, uv_poll_t), events, lluv_on_poll_start);

  if(err >= 0) lluv_handle_lock(L, handle, LLUV_LOCK_START);

  return lluv_return(L, handle, LLUV_START_CB(handle), err);
}
Beispiel #2
0
static int lluv_udp_send_(lua_State *L, lluv_handle_t *handle, struct sockaddr *sa, uv_buf_t *buf, size_t n){
  int err; lluv_req_t *req;

  if(lua_gettop(L) == 6){
    int ctx;
    lluv_check_callable(L, -2);
    ctx = luaL_ref(L, LLUV_LUA_REGISTRY);
    req = lluv_req_new(L, UV_UDP_SEND, handle);
    lluv_req_ref(L, req); /* string/table */
    req->ctx = ctx;
  }
  else{
    if(lua_gettop(L) == 4)
      lua_settop(L, 5);
    else
      lluv_check_args_with_cb(L, 5);

    req = lluv_req_new(L, UV_UDP_SEND, handle);
    lluv_req_ref(L, req); /* string/table */
  }

  err = uv_udp_send(LLUV_R(req, udp_send), LLUV_H(handle, uv_udp_t), buf, n, sa, lluv_on_udp_send_cb);

  return lluv_return_req(L, handle, req, err);
}
Beispiel #3
0
static int lluv_udp_start_recv(lua_State *L){
  lluv_handle_t *handle = lluv_check_udp(L, 1, LLUV_FLAG_OPEN);
  int err;

  lluv_check_args_with_cb(L, 2);
  LLUV_READ_CB(handle) = luaL_ref(L, LLUV_LUA_REGISTRY);

  err = uv_udp_recv_start(LLUV_H(handle, uv_udp_t), lluv_alloc_buffer_cb, lluv_on_udp_recv_cb);

  if(err >= 0) lluv_handle_lock(L, handle, LLUV_LOCK_READ);

  return lluv_return(L, handle, LLUV_READ_CB(handle), err);
}
Beispiel #4
0
static int lluv_signal_start(lua_State *L){
  lluv_handle_t *handle = lluv_check_signal(L, 1, LLUV_FLAG_OPEN);
  int signum = luaL_checkint(L, 2);
  int err;

  lluv_check_args_with_cb(L, 3);
  LLUV_START_CB(handle) = luaL_ref(L, LLUV_LUA_REGISTRY);

  err = uv_signal_start(LLUV_H(handle, uv_signal_t), lluv_on_signal_start, signum);

  if(err >= 0) lluv_handle_lock(L, handle, LLUV_LOCK_START);

  return lluv_return(L, handle, LLUV_START_CB(handle), err);
}
Beispiel #5
0
static int lluv_tcp_connect(lua_State *L){
  lluv_handle_t  *handle = lluv_check_tcp(L, 1, LLUV_FLAG_OPEN);
  struct sockaddr_storage sa; lluv_req_t *req;
  int err = lluv_check_addr(L, 2, &sa);

  if(err < 0){
    lua_settop(L, 3);
    lua_pushliteral(L, ":");lua_insert(L, -2);lua_concat(L, 3);
    return lluv_fail(L, handle->flags, LLUV_ERR_UV, err, lua_tostring(L, -1));
  }

  lluv_check_args_with_cb(L, 4);

  req = lluv_req_new(L, UV_CONNECT, handle);

  err = uv_tcp_connect(LLUV_R(req, connect), LLUV_H(handle, uv_tcp_t), (struct sockaddr *)&sa, lluv_on_stream_connect_cb);

  return lluv_return_req(L, handle, req, err);
}