I have a way to create, from Rust, an instance of an OpenVpn object in C++. It is represented by the opaque struct OpenVpnInstance
. I want to make the C++ OpenVpn object call open_vpn_receive
when it has data. However, obviously, it should call into my OpenVpn
struct instance, so it can insert into the OpenVpn::data
Vec
of buffers.
#[repr(C)]
pub struct OpenVpnInstance {
_private: [u8; 0],
}
type VpnReceive = extern "C" fn(*mut OpenVpnInstance, *mut c_uchar, *mut size_t) -> u8;
extern "C" {
pub fn openvpn_new(uri: *const c_char) -> *mut OpenVpnInstance;
pub fn openvpn_set_on_receive(instance: *mut OpenVpnInstance, on_receive: VpnReceive);
struct OpenVpn{
data: Vec<Vec<u8>>,
instance: *mut interface::OpenVpnInstance
}
extern "C" fn open_vpn_receive(instance: *mut interface::OpenVpnInstance, data: *mut c_uchar, size: *mut size_t) -> u8 {
//This function should be able to call `openvpn.data.insert` for the `openvpn: OpenVpn` that has this `instance`
}
How I can achieve that?