error issues

This commit is contained in:
ssrlive 2023-09-24 23:18:42 +08:00
parent 53daaed385
commit 8adfd8a0c1
2 changed files with 12 additions and 3 deletions

View file

@ -6,7 +6,7 @@ pub enum Error {
#[error("ctrlc::Error {0:?}")]
InterruptHandler(#[from] ctrlc::Error),
#[error("std::io::Error {0}")]
#[error(transparent)]
Io(#[from] std::io::Error),
#[error("TryFromIntError {0:?}")]
@ -84,4 +84,13 @@ impl From<&String> for Error {
}
}
impl From<Error> for std::io::Error {
fn from(err: Error) -> Self {
match err {
Error::Io(err) => err,
_ => std::io::Error::new(std::io::ErrorKind::Other, err),
}
}
}
pub type Result<T, E = Error> = std::result::Result<T, E>;

View file

@ -77,7 +77,7 @@ impl WinTunInterface {
let mask = Ipv4Addr::new(255, 255, 255, 0);
let gateway = Some(IpAddr::V4(Ipv4Addr::new(10, 1, 0, 1)));
adapter
.set_network_addresses_tuple(IpAddr::V4(address), IpAddr::V4(mask), gateway)
.set_network_addresses_tuple(address.into(), mask.into(), gateway)
.map_err(|e| io::Error::new(io::ErrorKind::Other, e))?;
let session = adapter
@ -99,7 +99,7 @@ impl WinTunInterface {
let packet = reader_session.receive_blocking()?;
let bytes = packet.bytes();
let result = { pipe_client_clone.lock().unwrap().write(bytes) };
let result = { pipe_client_clone.lock()?.write(bytes) };
match result {
Ok(_) => {}
Err(err) if err.kind() == io::ErrorKind::WouldBlock => {