Skip to content

Commit

Permalink
refactor(lua-bridge) rewrite for full yielding support
Browse files Browse the repository at this point in the history
  • Loading branch information
thibaultcha committed May 6, 2024
1 parent 36be351 commit 1e5aac7
Show file tree
Hide file tree
Showing 36 changed files with 1,329 additions and 848 deletions.
35 changes: 10 additions & 25 deletions lib/resty/wasmx/proxy_wasm.lua
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,6 @@ if subsystem == "http" then
int ngx_http_wasm_ffi_plan_attach(ngx_http_request_t *r,
ngx_wasm_plan_t *plan,
unsigned int isolation);
int ngx_http_wasm_ffi_start(ngx_http_request_t *r);
int ngx_http_wasm_ffi_set_property(ngx_http_request_t *r,
ngx_str_t *key,
ngx_str_t *value,
Expand Down Expand Up @@ -160,6 +159,16 @@ function _M.load(c_plan)
return nil, "failed loading plan"
end

if get_request() then
-- ffi_gc: hold a reference tied to the request lifecycle so users
-- don't have to (like our test suite).
if not ngx.ctx[_M] then
ngx.ctx[_M] = {}
end

ngx.ctx[_M][c_plan] = true
end

return true
end

Expand Down Expand Up @@ -215,30 +224,6 @@ function _M.attach(c_plan, opts)
end


function _M.start()
local phase = ngx.get_phase()
if phase ~= "rewrite" and phase ~= "access" then
error("start must be called from 'rewrite' or 'access' phase", 2)
end

local r = get_request()
if not r then
error("no request found", 2)
end

local rc = C.ngx_http_wasm_ffi_start(r)
if rc == FFI_ERROR then
return nil, "unknown error"
end

if rc == FFI_DECLINED then
return nil, "plan not loaded and attached"
end

return true
end


function _M.set_property(key, value)
if type(key) ~= "string" then
error("key must be a string", 2)
Expand Down
Loading

0 comments on commit 1e5aac7

Please sign in to comment.