Skip to content

Commit b361a81

Browse files
committed
Change the canary function to be the member function of WasmHandleBase
Signed-off-by: Ingwon Song <igsong@google.com>
1 parent c2f3676 commit b361a81

File tree

2 files changed

+10
-8
lines changed

2 files changed

+10
-8
lines changed

include/proxy-wasm/wasm.h

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -314,6 +314,10 @@ class WasmBase : public std::enable_shared_from_this<WasmBase> {
314314
std::shared_ptr<VmIdHandle> vm_id_handle_;
315315
};
316316

317+
using WasmHandleFactory = std::function<std::shared_ptr<WasmHandleBase>(std::string_view vm_id)>;
318+
using WasmHandleCloneFactory =
319+
std::function<std::shared_ptr<WasmHandleBase>(std::shared_ptr<WasmHandleBase> wasm)>;
320+
317321
// Handle which enables shutdown operations to run post deletion (e.g. post listener drain).
318322
class WasmHandleBase : public std::enable_shared_from_this<WasmHandleBase> {
319323
public:
@@ -324,6 +328,8 @@ class WasmHandleBase : public std::enable_shared_from_this<WasmHandleBase> {
324328
}
325329
}
326330

331+
bool canary(const std::shared_ptr<PluginBase> &plugin, const WasmHandleCloneFactory &clone_factory);
332+
327333
void kill() { wasm_base_ = nullptr; }
328334

329335
std::shared_ptr<WasmBase> &wasm() { return wasm_base_; }
@@ -335,10 +341,6 @@ class WasmHandleBase : public std::enable_shared_from_this<WasmHandleBase> {
335341
std::string makeVmKey(std::string_view vm_id, std::string_view configuration,
336342
std::string_view code);
337343

338-
using WasmHandleFactory = std::function<std::shared_ptr<WasmHandleBase>(std::string_view vm_id)>;
339-
using WasmHandleCloneFactory =
340-
std::function<std::shared_ptr<WasmHandleBase>(std::shared_ptr<WasmHandleBase> wasm)>;
341-
342344
// Returns nullptr on failure (i.e. initialization of the VM fails).
343345
std::shared_ptr<WasmHandleBase> createWasm(const std::string &vm_key, const std::string &code,
344346
const std::shared_ptr<PluginBase> &plugin,

src/wasm.cc

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -447,11 +447,11 @@ void WasmBase::finishShutdown() {
447447
}
448448
}
449449

450-
bool canary(std::shared_ptr<WasmHandleBase> &wasm_handle, const std::shared_ptr<PluginBase> &plugin,
450+
bool WasmHandleBase::canary(const std::shared_ptr<PluginBase> &plugin,
451451
const WasmHandleCloneFactory &clone_factory) {
452-
auto configuration_canary_handle = clone_factory(wasm_handle);
452+
auto configuration_canary_handle = clone_factory(shared_from_this());
453453
if (!configuration_canary_handle) {
454-
wasm_handle->wasm()->fail(FailState::UnableToCloneVm, "Failed to clone Base Wasm");
454+
this->wasm()->fail(FailState::UnableToCloneVm, "Failed to clone Base Wasm");
455455
return false;
456456
}
457457
if (!configuration_canary_handle->wasm()->initialize()) {
@@ -511,7 +511,7 @@ std::shared_ptr<WasmHandleBase> createWasm(const std::string &vm_key, const std:
511511
}
512512

513513
// Either creating new one or reusing the existing one, apply canary for each plugin.
514-
if (!canary(wasm_handle, plugin, clone_factory)) {
514+
if (!wasm_handle->canary(plugin, clone_factory)) {
515515
return nullptr;
516516
}
517517
return wasm_handle;

0 commit comments

Comments
 (0)