Skip to content

Commit 77f1630

Browse files
committed
code review: fixed several review comments.
1 parent 185f106 commit 77f1630

File tree

1 file changed

+13
-9
lines changed

1 file changed

+13
-9
lines changed

lib/ngx/resolver.lua

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ local base = require "resty.core.base"
22
local get_request = base.get_request
33
local ffi = require "ffi"
44
local C = ffi.C
5-
local ffi_new = ffi.new
65
local ffi_str = ffi.string
76
local ffi_gc = ffi.gc
87
local FFI_OK = base.FFI_OK
@@ -33,7 +32,8 @@ typedef struct {
3332
unsigned ipv6:1;
3433
} ngx_http_lua_resolver_ctx_t;
3534

36-
int ngx_http_lua_ffi_resolve(ngx_http_lua_resolver_ctx_t *ctx, const char *hostname);
35+
int ngx_http_lua_ffi_resolve(ngx_http_lua_resolver_ctx_t *ctx,
36+
const char *hostname);
3737

3838
void ngx_http_lua_ffi_resolver_destroy(ngx_http_lua_resolver_ctx_t *ctx);
3939
]]
@@ -47,18 +47,22 @@ local mt = {
4747
local Ctx = ffi.metatype("ngx_http_lua_resolver_ctx_t", mt)
4848

4949
function _M.resolve(hostname, ipv4, ipv6)
50-
assert(type(hostname) == "string", "hostname must be string")
51-
assert(ipv4 == nil or type(ipv4) == "boolean", "ipv4 must be boolean or nil")
52-
assert(ipv6 == nil or type(ipv6) == "boolean", "ipv6 must be boolean or nil")
53-
5450
local buf = get_string_buf(BUF_SIZE)
5551
local buf_size = get_size_ptr()
5652
buf_size[0] = BUF_SIZE
5753

58-
local ctx = Ctx({get_request(), buf, buf_size})
54+
local ctx = Ctx()
55+
ctx.request = get_request()
56+
ctx.buf = buf
57+
ctx.buf_size = buf_size
58+
59+
if ipv4 == nil or ipv4 then
60+
ctx.ipv4 = 1
61+
end
5962

60-
ctx.ipv4 = ipv4 == nil and 1 or ipv4
61-
ctx.ipv6 = ipv6 == nil and 0 or ipv6
63+
if ipv6 then
64+
ctx.ipv6 = 1
65+
end
6266

6367
local rc = C.ngx_http_lua_ffi_resolve(ctx, hostname)
6468

0 commit comments

Comments
 (0)