From ce238a708d7c0dc7b45535316c0a6faba33782a1 Mon Sep 17 00:00:00 2001 From: Ilya Guterman Date: Sun, 23 Aug 2020 01:34:47 +0300 Subject: [PATCH] use open interface --- src/lib.rs | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/lib.rs b/src/lib.rs index 25da230..f28da3b 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -33,10 +33,10 @@ impl std::io::Read for ClonableTcpStream { } } -thread_local!(static MSP: RefCell = RefCell::new(Msp::new(0, Duration::from_millis(0), false))); +thread_local!(static MSP: RefCell> = RefCell::new(None)); #[no_mangle] -pub extern fn start(s: *const c_char) { +pub extern fn open(s: *const c_char) { let c_str = unsafe { assert!(!s.is_null()); @@ -44,8 +44,8 @@ pub extern fn start(s: *const c_char) { }; let stream = ClonableTcpStream(TcpStream::connect(c_str.to_str().unwrap()).unwrap()); MSP.with(|msp_cell| { - let msp = msp_cell.borrow_mut(); - msp.start(stream); + let msp = Some(Msp::open(stream, 0, Duration::from_millis(0), false)); + msp_cell.replace(msp); }); } @@ -58,7 +58,7 @@ pub extern fn set_raw_rc(array: *const c_ushort, length: c_uint) { slice::from_raw_parts(array, length as usize) }; block_on(async { - msp.set_raw_rc(channels.to_vec()).await.unwrap(); + msp.as_ref().unwrap().set_raw_rc(channels.to_vec()).await.unwrap(); }); }); }