Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

avoid panic/unwind on extern "C" fnc #288

Merged
merged 1 commit into from
Jan 15, 2024
Merged
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
14 changes: 8 additions & 6 deletions livekit-ffi/src/cabi.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ use server::FfiDataBuffer;
use crate::{
proto,
server::{self, FfiConfig},
FfiHandleId, FFI_SERVER,
FfiHandleId, FFI_SERVER, INVALID_HANDLE,
};

/// # SAFTEY: The "C" callback must be threadsafe and not block
Expand Down Expand Up @@ -39,17 +39,19 @@ pub unsafe extern "C" fn livekit_ffi_request(
res_len: *mut usize,
) -> FfiHandleId {
let data = unsafe { std::slice::from_raw_parts(data, len) };
let res = match proto::FfiRequest::decode(data) {
Ok(res) => res,
let req = match proto::FfiRequest::decode(data) {
Ok(req) => req,
Err(err) => {
panic!("failed to decode request: {}", err);
log::error!("failed to decode request: {:?}", err);
return INVALID_HANDLE;
}
};

let res = match server::requests::handle_request(&FFI_SERVER, res) {
let res = match server::requests::handle_request(&FFI_SERVER, req.clone()) {
Ok(res) => res,
Err(err) => {
panic!("failed to handle request: {}", err);
log::error!("failed to handle request {:?}: {:?}", req, err);
return INVALID_HANDLE;
}
}
.encode_to_vec();
Expand Down
Loading