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); }
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); }