Skip to content

Commit

Permalink
bugfix: add runtime to ffi::listen (#512)
Browse files Browse the repository at this point in the history
* rm async listen
* bump version
  • Loading branch information
RyanKung authored Jan 2, 2024
1 parent e54f870 commit ccfe2cf
Show file tree
Hide file tree
Showing 6 changed files with 12 additions and 28 deletions.
10 changes: 5 additions & 5 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ resolver = "2"
members = ["core", "transport", "node", "rpc", "derive"]

[workspace.package]
version = "0.5.0"
version = "0.5.1"
edition = "2021"
license = "GPL-3.0"
authors = ["RND <dev@ringsnetwork.io>"]
Expand Down
8 changes: 0 additions & 8 deletions examples/ffi/rings.h
Original file line number Diff line number Diff line change
Expand Up @@ -76,14 +76,6 @@ void init_logging(enum LogLevel level);
*/
void listen(const struct ProviderPtr *provider_ptr);

/**
* Start message listening and stabilization
* This function will launch listener in a new thread
* # Safety
* Listen function accept a ProviderPtr and will unsafety cast it into Arc based Provider
*/
void async_listen(const struct ProviderPtr *provider_ptr);

/**
* Request internal rpc api
* # Safety
Expand Down
2 changes: 1 addition & 1 deletion examples/ffi/rings.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ def create_provider(acc,
gen_signer(acc),
ffi.addressof(callback),
)
rings.async_listen(ffi.addressof(provider))
rings.listen(ffi.addressof(provider))
return provider


Expand Down
16 changes: 4 additions & 12 deletions node/src/provider/ffi.rs
Original file line number Diff line number Diff line change
Expand Up @@ -160,26 +160,18 @@ impl From<&ProviderWithRuntime> for ProviderPtr {
}
}

/// Start message listening and stabilization
/// # Safety
/// Listen function accept a ProviderPtr and will unsafety cast it into Arc based Provider
#[no_mangle]
pub extern "C" fn listen(provider_ptr: *const ProviderPtr) {
let provider: ProviderWithRuntime =
ProviderWithRuntime::from_raw(provider_ptr).expect("Provider ptr is invalid");
executor::block_on(provider.provider.processor.listen());
}

/// Start message listening and stabilization
/// This function will launch listener in a new thread
/// # Safety
/// Listen function accept a ProviderPtr and will unsafety cast it into Arc based Provider
#[no_mangle]
pub extern "C" fn async_listen(provider_ptr: *const ProviderPtr) {
pub extern "C" fn listen(provider_ptr: *const ProviderPtr) {
let provider: ProviderWithRuntime =
ProviderWithRuntime::from_raw(provider_ptr).expect("Provider ptr is invalid");
std::thread::spawn(move || {
executor::block_on(provider.provider.processor.listen());
provider.runtime.block_on(async {
provider.provider.processor.listen().await;
})
});
}

Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"RND <dev@ringsnetwork.io>"
],
"description": "Rings is a structured peer-to-peer network implementation using WebRTC, Chord algorithm, and full WebAssembly (WASM) support.\n",
"version": "0.5.0",
"version": "0.5.1",
"license": "GPL-3.0",
"repository": {
"type": "git",
Expand Down

0 comments on commit ccfe2cf

Please sign in to comment.