Skip to content

Commit

Permalink
avoid panic/unwind on extern "C" fnc (#288)
Browse files Browse the repository at this point in the history
  • Loading branch information
theomonnom authored Jan 15, 2024
1 parent a5d25e3 commit 7623f27
Showing 1 changed file with 8 additions and 6 deletions.
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

0 comments on commit 7623f27

Please sign in to comment.