@@ -8,7 +8,10 @@ use idevice::{
88 provider:: IdeviceProvider ,
99} ;
1010
11- use crate :: { IdeviceFfiError , IdeviceHandle , RUNTIME , ffi_err, provider:: IdeviceProviderHandle } ;
11+ use crate :: {
12+ IdeviceFfiError , IdeviceHandle , LOCAL_RUNTIME , ffi_err, provider:: IdeviceProviderHandle ,
13+ run_sync, run_sync_local,
14+ } ;
1215
1316pub struct AfcClientHandle ( pub AfcClient ) ;
1417
@@ -34,7 +37,7 @@ pub unsafe extern "C" fn afc_client_connect(
3437 return ffi_err ! ( IdeviceError :: FfiInvalidArg ) ;
3538 }
3639
37- let res = RUNTIME . block_on ( async {
40+ let res = run_sync_local ( async {
3841 let provider_ref: & dyn IdeviceProvider = unsafe { & * ( * provider) . 0 } ;
3942
4043 AfcClient :: connect ( provider_ref) . await
@@ -122,7 +125,7 @@ pub unsafe extern "C" fn afc_list_directory(
122125 // Use to_string_lossy to handle non-UTF8 paths
123126 let path = path_cstr. to_string_lossy ( ) ;
124127
125- let res: Result < Vec < String > , IdeviceError > = RUNTIME . block_on ( async move {
128+ let res: Result < Vec < String > , IdeviceError > = run_sync_local ( async move {
126129 // SAFETY: We're assuming client is a valid pointer here
127130 let client_ref = unsafe { & mut ( * client) . 0 } ;
128131 client_ref. list_dir ( & path. to_string ( ) ) . await
@@ -194,7 +197,7 @@ pub unsafe extern "C" fn afc_make_directory(
194197 Err ( _) => return ffi_err ! ( IdeviceError :: FfiInvalidArg ) ,
195198 } ;
196199
197- let res: Result < ( ) , IdeviceError > = RUNTIME . block_on ( async move {
200+ let res: Result < ( ) , IdeviceError > = run_sync_local ( async move {
198201 let client_ref = unsafe { & mut ( * client) . 0 } ;
199202 client_ref. mk_dir ( path) . await
200203 } ) ;
@@ -246,7 +249,7 @@ pub unsafe extern "C" fn afc_get_file_info(
246249 Err ( _) => return ffi_err ! ( IdeviceError :: FfiInvalidArg ) ,
247250 } ;
248251
249- let res: Result < FileInfo , IdeviceError > = RUNTIME . block_on ( async move {
252+ let res: Result < FileInfo , IdeviceError > = run_sync_local ( async move {
250253 let client_ref = unsafe { & mut ( * client) . 0 } ;
251254 client_ref. get_file_info ( path) . await
252255 } ) ;
@@ -331,7 +334,7 @@ pub unsafe extern "C" fn afc_get_device_info(
331334 return ffi_err ! ( IdeviceError :: FfiInvalidArg ) ;
332335 }
333336
334- let res: Result < DeviceInfo , IdeviceError > = RUNTIME . block_on ( async move {
337+ let res: Result < DeviceInfo , IdeviceError > = run_sync_local ( async move {
335338 let client_ref = unsafe { & mut ( * client) . 0 } ;
336339 client_ref. get_device_info ( ) . await
337340 } ) ;
@@ -395,7 +398,7 @@ pub unsafe extern "C" fn afc_remove_path(
395398 Err ( _) => return ffi_err ! ( IdeviceError :: FfiInvalidArg ) ,
396399 } ;
397400
398- let res: Result < ( ) , IdeviceError > = RUNTIME . block_on ( async move {
401+ let res: Result < ( ) , IdeviceError > = run_sync_local ( async move {
399402 let client_ref = unsafe { & mut ( * client) . 0 } ;
400403 client_ref. remove ( path) . await
401404 } ) ;
@@ -433,7 +436,7 @@ pub unsafe extern "C" fn afc_remove_path_and_contents(
433436 Err ( _) => return ffi_err ! ( IdeviceError :: FfiInvalidArg ) ,
434437 } ;
435438
436- let res: Result < ( ) , IdeviceError > = RUNTIME . block_on ( async move {
439+ let res: Result < ( ) , IdeviceError > = run_sync_local ( async move {
437440 let client_ref = unsafe { & mut ( * client) . 0 } ;
438441 client_ref. remove_all ( path) . await
439442 } ) ;
@@ -506,7 +509,7 @@ pub unsafe extern "C" fn afc_file_open(
506509
507510 let mode = mode. into ( ) ;
508511
509- let res: Result < * mut AfcFileHandle , IdeviceError > = RUNTIME . block_on ( async move {
512+ let res: Result < * mut AfcFileHandle , IdeviceError > = LOCAL_RUNTIME . block_on ( async move {
510513 let client_ref = unsafe { & mut ( * client) . 0 } ;
511514 let result = client_ref. open ( path, mode) . await ;
512515 match result {
@@ -544,7 +547,7 @@ pub unsafe extern "C" fn afc_file_close(handle: *mut AfcFileHandle) -> *mut Idev
544547 }
545548
546549 let fd = unsafe { Box :: from_raw ( handle as * mut idevice:: afc:: file:: FileDescriptor ) } ;
547- let res: Result < ( ) , IdeviceError > = RUNTIME . block_on ( async move { fd. close ( ) . await } ) ;
550+ let res: Result < ( ) , IdeviceError > = run_sync ( async move { fd. close ( ) . await } ) ;
548551
549552 match res {
550553 Ok ( _) => null_mut ( ) ,
@@ -575,7 +578,7 @@ pub unsafe extern "C" fn afc_file_read(
575578 }
576579
577580 let fd = unsafe { & mut * ( handle as * mut idevice:: afc:: file:: FileDescriptor ) } ;
578- let res: Result < Vec < u8 > , IdeviceError > = RUNTIME . block_on ( async move { fd. read ( ) . await } ) ;
581+ let res: Result < Vec < u8 > , IdeviceError > = run_sync ( async move { fd. read ( ) . await } ) ;
579582
580583 match res {
581584 Ok ( bytes) => {
@@ -617,7 +620,7 @@ pub unsafe extern "C" fn afc_file_write(
617620 let fd = unsafe { & mut * ( handle as * mut idevice:: afc:: file:: FileDescriptor ) } ;
618621 let data_slice = unsafe { std:: slice:: from_raw_parts ( data, length) } ;
619622
620- let res: Result < ( ) , IdeviceError > = RUNTIME . block_on ( async move { fd. write ( data_slice) . await } ) ;
623+ let res: Result < ( ) , IdeviceError > = run_sync ( async move { fd. write ( data_slice) . await } ) ;
621624
622625 match res {
623626 Ok ( _) => null_mut ( ) ,
@@ -674,7 +677,7 @@ pub unsafe extern "C" fn afc_make_link(
674677 AfcLinkType :: Symbolic => idevice:: afc:: opcode:: LinkType :: Symlink ,
675678 } ;
676679
677- let res: Result < ( ) , IdeviceError > = RUNTIME . block_on ( async move {
680+ let res: Result < ( ) , IdeviceError > = run_sync_local ( async move {
678681 let client_ref = unsafe { & mut ( * client) . 0 } ;
679682 client_ref. link ( target, source, link_type) . await
680683 } ) ;
@@ -720,7 +723,7 @@ pub unsafe extern "C" fn afc_rename_path(
720723 Err ( _) => return ffi_err ! ( IdeviceError :: FfiInvalidArg ) ,
721724 } ;
722725
723- let res: Result < ( ) , IdeviceError > = RUNTIME . block_on ( async move {
726+ let res: Result < ( ) , IdeviceError > = run_sync_local ( async move {
724727 let client_ref = unsafe { & mut ( * client) . 0 } ;
725728 client_ref. rename ( source, target) . await
726729 } ) ;
0 commit comments