Skip to content

Commit

Permalink
code review: fixed several review comments.
Browse files Browse the repository at this point in the history
  • Loading branch information
slimboyfat committed Mar 14, 2019
1 parent 185f106 commit 77f1630
Showing 1 changed file with 13 additions and 9 deletions.
22 changes: 13 additions & 9 deletions lib/ngx/resolver.lua
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ local base = require "resty.core.base"
local get_request = base.get_request
local ffi = require "ffi"
local C = ffi.C
local ffi_new = ffi.new
local ffi_str = ffi.string
local ffi_gc = ffi.gc
local FFI_OK = base.FFI_OK
Expand Down Expand Up @@ -33,7 +32,8 @@ typedef struct {
unsigned ipv6:1;
} ngx_http_lua_resolver_ctx_t;

int ngx_http_lua_ffi_resolve(ngx_http_lua_resolver_ctx_t *ctx, const char *hostname);
int ngx_http_lua_ffi_resolve(ngx_http_lua_resolver_ctx_t *ctx,
const char *hostname);

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

function _M.resolve(hostname, ipv4, ipv6)
assert(type(hostname) == "string", "hostname must be string")
assert(ipv4 == nil or type(ipv4) == "boolean", "ipv4 must be boolean or nil")
assert(ipv6 == nil or type(ipv6) == "boolean", "ipv6 must be boolean or nil")

local buf = get_string_buf(BUF_SIZE)
local buf_size = get_size_ptr()
buf_size[0] = BUF_SIZE

local ctx = Ctx({get_request(), buf, buf_size})
local ctx = Ctx()
ctx.request = get_request()
ctx.buf = buf
ctx.buf_size = buf_size

if ipv4 == nil or ipv4 then
ctx.ipv4 = 1
end

ctx.ipv4 = ipv4 == nil and 1 or ipv4
ctx.ipv6 = ipv6 == nil and 0 or ipv6
if ipv6 then
ctx.ipv6 = 1
end

local rc = C.ngx_http_lua_ffi_resolve(ctx, hostname)

Expand Down

0 comments on commit 77f1630

Please sign in to comment.