Skip to content
This repository was archived by the owner on Oct 17, 2020. It is now read-only.

use open interface #1

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,19 +33,19 @@ impl std::io::Read for ClonableTcpStream {
}
}

thread_local!(static MSP: RefCell<Msp> = RefCell::new(Msp::new(0, Duration::from_millis(0), false)));
thread_local!(static MSP: RefCell<Option<Msp>> = 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());

CStr::from_ptr(s)
};
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);
});
}

Expand All @@ -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();
});
});
}
Expand Down