| 491 | } |
| 492 | |
| 493 | static int |
| 494 | ts_lua_host_lookup(lua_State *L) |
| 495 | { |
| 496 | const char *host; |
| 497 | size_t host_len = 0; |
| 498 | TSAction action; |
| 499 | TSCont contp; |
| 500 | ts_lua_async_item *ai; |
| 501 | ts_lua_cont_info *ci; |
| 502 | |
| 503 | ci = ts_lua_get_cont_info(L); |
| 504 | if (ci == nullptr) { |
| 505 | TSError("[ts_lua][%s] no cont info found", __FUNCTION__); |
| 506 | TSReleaseAssert(!"Unexpected fetch of cont info"); |
| 507 | return 0; |
| 508 | } |
| 509 | |
| 510 | if (lua_gettop(L) != 1) { |
| 511 | TSError("[ts_lua][%s] ts.host_lookup need at least one parameter", __FUNCTION__); |
| 512 | return 0; |
| 513 | } |
| 514 | |
| 515 | host = luaL_checklstring(L, 1, &host_len); |
| 516 | |
| 517 | contp = TSContCreate(ts_lua_host_lookup_handler, ci->mutex); |
| 518 | ai = ts_lua_async_create_item(contp, ts_lua_host_lookup_cleanup, nullptr, ci); |
| 519 | |
| 520 | TSContDataSet(contp, ai); |
| 521 | action = TSHostLookup(contp, host, host_len); |
| 522 | if (!TSActionDone(action)) { |
| 523 | ai->data = (void *)action; |
| 524 | return lua_yield(L, 0); |
| 525 | } |
| 526 | |
| 527 | return 1; |
| 528 | } |
| 529 | |
| 530 | static int |
| 531 | ts_lua_host_lookup_handler(TSCont contp, TSEvent event, void *edata) |
nothing calls this directly
no test coverage detected