Use llarp::Context::CallSafe() for vpn AsyncClose()

pull/1314/head
Stephen Shelton 4 years ago
parent ba92d12203
commit d85e48c9d0
No known key found for this signature in database
GPG Key ID: EE4BADACCE8B631C

@ -3,6 +3,11 @@
#include <stdint.h>
#include <unistd.h>
namespace llarp
{
struct Context;
}
#ifdef __cplusplus
extern "C"
{
@ -48,7 +53,7 @@ extern "C"
/// initialize llarp_vpn_io private implementation
/// returns false if either parameter is nullptr
bool
llarp_vpn_io_init(struct llarp_main* m, struct llarp_vpn_io* io);
llarp_vpn_io_init(llarp::Context* ctx, struct llarp_vpn_io* io);
/// get the packet pipe for writing IP packets to lokinet internals
/// returns nullptr if llarp_vpn_io is nullptr or not initialized

@ -297,11 +297,11 @@ extern "C"
}
bool
llarp_vpn_io_init(struct llarp_main* ptr, struct llarp_vpn_io* io)
llarp_vpn_io_init(llarp::Context* ctx, struct llarp_vpn_io* io)
{
if (io == nullptr || ptr == nullptr)
if (io == nullptr || ctx == nullptr)
return false;
llarp_vpn_io_impl* impl = new llarp_vpn_io_impl(ptr, io);
llarp_vpn_io_impl* impl = new llarp_vpn_io_impl(ctx, io);
io->impl = impl;
return true;
}

@ -10,7 +10,10 @@ llarp_vpn_io_impl::AsyncClose()
writer.queue.disable();
// TODO: call asynchronously
Expunge();
if (ctx)
ctx->CallSafe([this]() { Expunge(); });
else
Expunge();
}
void

@ -2,6 +2,7 @@
#define LLARP_EV_VPNIO_HPP
#include <net/ip_packet.hpp>
#include <util/thread/queue.hpp>
#include <llarp.hpp>
#include <functional>
struct llarp_main;
@ -26,12 +27,12 @@ struct llarp_vpn_pkt_reader : public llarp_vpn_pkt_queue
struct llarp_vpn_io_impl
{
llarp_vpn_io_impl(llarp_main* p, llarp_vpn_io* io) : ptr(p), parent(io)
llarp_vpn_io_impl(llarp::Context* c, llarp_vpn_io* io) : ctx(c), parent(io)
{
}
~llarp_vpn_io_impl() = default;
llarp_main* ptr;
llarp::Context* ctx;
llarp_vpn_io* parent;
llarp_vpn_pkt_writer writer;

Loading…
Cancel
Save