mirror of
https://github.com/jkcoxson/idevice.git
synced 2026-03-02 06:26:15 +01:00
Use platform-independent socket for FFI
Windows is truly awful Remove config.toml
This commit is contained in:
@@ -136,22 +136,23 @@ pub unsafe extern "C" fn idevice_new(
|
||||
/// `addr` must be a valid sockaddr
|
||||
/// `label` must be a valid null-terminated C string
|
||||
/// `idevice` must be a valid, non-null pointer to a location where the handle will be stored
|
||||
#[cfg(unix)]
|
||||
#[unsafe(no_mangle)]
|
||||
pub unsafe extern "C" fn idevice_new_tcp_socket(
|
||||
addr: *const libc::sockaddr,
|
||||
addr_len: libc::socklen_t,
|
||||
addr: *const idevice_sockaddr,
|
||||
addr_len: idevice_socklen_t,
|
||||
label: *const c_char,
|
||||
idevice: *mut *mut IdeviceHandle,
|
||||
) -> *mut IdeviceFfiError {
|
||||
if addr.is_null() {
|
||||
log::error!("socket addr null pointer");
|
||||
if addr.is_null() || label.is_null() || idevice.is_null() {
|
||||
log::error!("null pointer(s) to idevice_new_tcp_socket");
|
||||
return ffi_err!(IdeviceError::FfiInvalidArg);
|
||||
}
|
||||
let addr = addr as *const SockAddr;
|
||||
|
||||
// Convert C string to Rust string
|
||||
let label = match unsafe { CStr::from_ptr(label).to_str() } {
|
||||
Ok(s) => s,
|
||||
Err(_) => return ffi_err!(IdeviceError::FfiInvalidArg),
|
||||
Err(_) => return ffi_err!(IdeviceError::FfiInvalidString),
|
||||
};
|
||||
|
||||
let addr = match util::c_socket_to_rust(addr, addr_len) {
|
||||
@@ -159,9 +160,10 @@ pub unsafe extern "C" fn idevice_new_tcp_socket(
|
||||
Err(e) => return ffi_err!(e),
|
||||
};
|
||||
|
||||
let device: Result<idevice::Idevice, idevice::IdeviceError> = RUNTIME.block_on(async move {
|
||||
Ok(idevice::Idevice::new(
|
||||
Box::new(tokio::net::TcpStream::connect(addr).await?),
|
||||
let device = RUNTIME.block_on(async move {
|
||||
let stream = tokio::net::TcpStream::connect(addr).await?;
|
||||
Ok::<idevice::Idevice, idevice::IdeviceError>(idevice::Idevice::new(
|
||||
Box::new(stream),
|
||||
label,
|
||||
))
|
||||
});
|
||||
@@ -170,7 +172,7 @@ pub unsafe extern "C" fn idevice_new_tcp_socket(
|
||||
Ok(dev) => {
|
||||
let boxed = Box::new(IdeviceHandle(dev));
|
||||
unsafe { *idevice = Box::into_raw(boxed) };
|
||||
null_mut()
|
||||
std::ptr::null_mut()
|
||||
}
|
||||
Err(e) => ffi_err!(e),
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user