mirror of
https://github.com/jkcoxson/idevice.git
synced 2026-03-02 22:46:14 +01:00
Fix Windows building
This commit is contained in:
@@ -1,10 +1,13 @@
|
|||||||
// Jackson Coxson
|
// Jackson Coxson
|
||||||
|
|
||||||
use std::{
|
use std::{
|
||||||
net::{AddrParseError, IpAddr, Ipv4Addr, Ipv6Addr, SocketAddr, SocketAddrV4},
|
net::{AddrParseError, IpAddr, Ipv4Addr, Ipv6Addr, SocketAddr},
|
||||||
str::FromStr,
|
str::FromStr,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
#[cfg(not(unix))]
|
||||||
|
use std::net::SocketAddrV4;
|
||||||
|
|
||||||
use log::debug;
|
use log::debug;
|
||||||
use tokio::io::{AsyncReadExt, AsyncWriteExt};
|
use tokio::io::{AsyncReadExt, AsyncWriteExt};
|
||||||
|
|
||||||
@@ -36,6 +39,7 @@ pub struct UsbmuxdConnection {
|
|||||||
|
|
||||||
#[derive(Clone, Debug)]
|
#[derive(Clone, Debug)]
|
||||||
pub enum UsbmuxdAddr {
|
pub enum UsbmuxdAddr {
|
||||||
|
#[cfg(unix)]
|
||||||
UnixSocket(String),
|
UnixSocket(String),
|
||||||
TcpSocket(SocketAddr),
|
TcpSocket(SocketAddr),
|
||||||
}
|
}
|
||||||
@@ -46,6 +50,7 @@ impl UsbmuxdAddr {
|
|||||||
|
|
||||||
pub async fn to_socket(&self) -> Result<Box<dyn ReadWrite>, IdeviceError> {
|
pub async fn to_socket(&self) -> Result<Box<dyn ReadWrite>, IdeviceError> {
|
||||||
Ok(match self {
|
Ok(match self {
|
||||||
|
#[cfg(unix)]
|
||||||
Self::UnixSocket(addr) => Box::new(tokio::net::UnixStream::connect(addr).await?),
|
Self::UnixSocket(addr) => Box::new(tokio::net::UnixStream::connect(addr).await?),
|
||||||
Self::TcpSocket(addr) => Box::new(tokio::net::TcpStream::connect(addr).await?),
|
Self::TcpSocket(addr) => Box::new(tokio::net::TcpStream::connect(addr).await?),
|
||||||
})
|
})
|
||||||
@@ -59,11 +64,14 @@ impl UsbmuxdAddr {
|
|||||||
pub fn from_env_var() -> Result<Self, AddrParseError> {
|
pub fn from_env_var() -> Result<Self, AddrParseError> {
|
||||||
Ok(match std::env::var("USBMUXD_SOCKET_ADDRESS") {
|
Ok(match std::env::var("USBMUXD_SOCKET_ADDRESS") {
|
||||||
Ok(var) => {
|
Ok(var) => {
|
||||||
|
#[cfg(unix)]
|
||||||
if var.contains(':') {
|
if var.contains(':') {
|
||||||
Self::TcpSocket(SocketAddr::from_str(&var)?)
|
Self::TcpSocket(SocketAddr::from_str(&var)?)
|
||||||
} else {
|
} else {
|
||||||
Self::UnixSocket(var)
|
Self::UnixSocket(var)
|
||||||
}
|
}
|
||||||
|
#[cfg(not(unix))]
|
||||||
|
Self::TcpSocket(SocketAddr::from_str(&var)?)
|
||||||
}
|
}
|
||||||
Err(_) => Self::default(),
|
Err(_) => Self::default(),
|
||||||
})
|
})
|
||||||
@@ -72,16 +80,15 @@ impl UsbmuxdAddr {
|
|||||||
|
|
||||||
impl Default for UsbmuxdAddr {
|
impl Default for UsbmuxdAddr {
|
||||||
fn default() -> Self {
|
fn default() -> Self {
|
||||||
if cfg!(target_os = "windows") {
|
#[cfg(not(unix))]
|
||||||
|
{
|
||||||
Self::TcpSocket(SocketAddr::V4(SocketAddrV4::new(
|
Self::TcpSocket(SocketAddr::V4(SocketAddrV4::new(
|
||||||
Ipv4Addr::new(127, 0, 0, 1),
|
Ipv4Addr::new(127, 0, 0, 1),
|
||||||
Self::DEFAULT_PORT,
|
Self::DEFAULT_PORT,
|
||||||
)))
|
)))
|
||||||
} else if cfg!(target_os = "macos") || cfg!(target_os = "linux") {
|
|
||||||
Self::UnixSocket(Self::SOCKET_FILE.to_string())
|
|
||||||
} else {
|
|
||||||
panic!("Undefined OS for default UsbmuxdAddr")
|
|
||||||
}
|
}
|
||||||
|
#[cfg(unix)]
|
||||||
|
Self::UnixSocket(Self::SOCKET_FILE.to_string())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user