From 7212b7a28b83e8df90861d55a655ac8a7eafcd48 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9bastien=20Blin?= <sebastien.blin@savoirfairelinux.com> Date: Thu, 17 Oct 2019 11:35:56 -0400 Subject: [PATCH] rust: change put api --- rust/examples/dhtnode.rs | 14 ++++++-------- rust/src/lib.rs | 4 ++-- 2 files changed, 8 insertions(+), 10 deletions(-) diff --git a/rust/examples/dhtnode.rs b/rust/examples/dhtnode.rs index 8ab4001a..dd7c4a25 100644 --- a/rust/examples/dhtnode.rs +++ b/rust/examples/dhtnode.rs @@ -57,18 +57,16 @@ fn main() { }; let ptr = &mut handler as *mut _ as *mut c_void; - println!("Start listening /foo"); - let token = dht.listen(&InfoHash::get("foo"), value_cb, ptr); - thread::sleep(ten_secs); - println!("Stop listening /foo"); - dht.cancel_listen(&InfoHash::get("foo"), token); + //println!("Start listening /foo"); + //let token = dht.listen(&InfoHash::get("foo"), value_cb, ptr); + //thread::sleep(ten_secs); + //println!("Stop listening /foo"); + //dht.cancel_listen(&InfoHash::get("foo"), token); //loop { println!("Get /alice"); dht.get(&InfoHash::get("alice"), get_cb, done_cb, ptr); let v = Value::new("hi!"); - // TODO put value - // TODO check drop - dht.put(&InfoHash::get("bob"), Box::into_raw(v), done_cb, ptr); + dht.put(&InfoHash::get("bob"), v, done_cb, ptr); //thread::sleep(ten_secs); //} } \ No newline at end of file diff --git a/rust/src/lib.rs b/rust/src/lib.rs index 66945aa3..d9b6adfd 100644 --- a/rust/src/lib.rs +++ b/rust/src/lib.rs @@ -112,12 +112,12 @@ impl DhtRunner { } } - pub fn put(&mut self, h: &InfoHash, v: *const Value, + pub fn put(&mut self, h: &InfoHash, v: Box<Value>, done_cb: extern fn(bool, *mut c_void), cb_user_data: *mut c_void) { unsafe { - dht_runner_put(&mut *self, h, v, done_cb, cb_user_data) + dht_runner_put(&mut *self, h, &*v, done_cb, cb_user_data) } } -- GitLab