diff options
author | Justus Winter <justus@sequoia-pgp.org> | 2019-08-19 15:36:47 +0200 |
---|---|---|
committer | Justus Winter <justus@sequoia-pgp.org> | 2019-08-19 15:36:47 +0200 |
commit | 63637840a92f237b21369f2b8cb2c202d33613fc (patch) | |
tree | 0ee483ea20eae9bc63297ac8a2c75f4d56ccea4e /ffi | |
parent | bcd5ab8751c14f4ac48a2ea8b7d90163eb306b5f (diff) |
net: Drop the sync variant.
- The sync wrapper hide the async nature of the implementation, and
while this may seem convenient, it may cause subtle problems if it
is invoked from a different event loop.
- Furthermore, 'async' is a reserved keyword in the 2018 edition,
requiring awkward escaping.
- Fixes #307.
Diffstat (limited to 'ffi')
-rw-r--r-- | ffi/Cargo.toml | 1 | ||||
-rw-r--r-- | ffi/src/net.rs | 8 |
2 files changed, 7 insertions, 2 deletions
diff --git a/ffi/Cargo.toml b/ffi/Cargo.toml index 6af751b7..35d2e875 100644 --- a/ffi/Cargo.toml +++ b/ffi/Cargo.toml @@ -35,6 +35,7 @@ memsec = "0.5.6" native-tls = "0.2.0" nettle = "5.0" time = "0.1.40" +tokio-core = "0.1" [dev-dependencies] filetime = "0.2" diff --git a/ffi/src/net.rs b/ffi/src/net.rs index d99da30c..5709e09a 100644 --- a/ffi/src/net.rs +++ b/ffi/src/net.rs @@ -33,6 +33,7 @@ use std::ptr; use std::slice; extern crate sequoia_openpgp as openpgp; +extern crate tokio_core; use sequoia_net::KeyServer; @@ -121,7 +122,8 @@ fn sq_keyserver_get(ctx: *mut Context, let ks = ffi_param_ref_mut!(ks); let id = id.ref_raw(); - ks.get(&id).move_into_raw(Some(ctx.errp())) + let mut core = ffi_try_or!(tokio_core::reactor::Core::new(), None); + core.run(ks.get(&id)).move_into_raw(Some(ctx.errp())) } /// Sends the given key to the server. @@ -137,5 +139,7 @@ fn sq_keyserver_send(ctx: *mut Context, let ks = ffi_param_ref_mut!(ks); let tpk = tpk.ref_raw(); - ffi_try_status!(ks.send(tpk)) + ffi_try_status!(tokio_core::reactor::Core::new() + .map_err(|e| e.into()) + .and_then(|mut core| core.run(ks.send(tpk)))) } |