Beispiel #1
0
static int lluv_udp_try_send(lua_State *L) {
    lluv_handle_t *handle = lluv_check_udp(L, 1, LLUV_FLAG_OPEN);
    struct sockaddr_storage sa;
    int err = lluv_check_addr(L, 2, &sa);
    size_t len;
    const char *str = luaL_checklstring(L, 4, &len);
    uv_buf_t buf = uv_buf_init((char*)str, len);

    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_none(L, 3);

    err = uv_udp_try_send(LLUV_H(handle, uv_udp_t), &buf, 1, (struct sockaddr*)&sa);
    if(err < 0) {
        return lluv_fail(L, handle->flags, LLUV_ERR_UV, err, NULL);
    }

    lua_pushinteger(L, err);
    return 1;
}
Beispiel #2
0
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;
}