1.增加错误枚举

This commit is contained in:
lubeilin
2023-01-15 19:19:04 +08:00
parent 9820c56be6
commit 206c543e8c
2 changed files with 9 additions and 1 deletions
+4 -1
View File
@@ -268,8 +268,11 @@ fn other_handle(
fast_registration(&udp, server_addr)?; fast_registration(&udp, server_addr)?;
} }
} }
InErrorPacket::AddressExhausted => {
return Err(Error::Stop("IP address has been exhausted".to_string()));
}
InErrorPacket::OtherError(e) => { InErrorPacket::OtherError(e) => {
log::warn!("OtherError {:?}", e.message()); log::error!("OtherError {:?}", e.message());
} }
} }
} }
+5
View File
@@ -4,6 +4,7 @@ use crate::error::*;
pub enum Protocol { pub enum Protocol {
TokenError, TokenError,
Disconnect, Disconnect,
AddressExhausted,
Other(u8), Other(u8),
} }
@@ -12,6 +13,7 @@ impl From<u8> for Protocol {
match value { match value {
1 => Self::TokenError, 1 => Self::TokenError,
2 => Self::Disconnect, 2 => Self::Disconnect,
3 => Self::AddressExhausted,
val => Self::Other(val), val => Self::Other(val),
} }
} }
@@ -22,6 +24,7 @@ impl Into<u8> for Protocol {
match self { match self {
Protocol::TokenError => 1, Protocol::TokenError => 1,
Protocol::Disconnect => 2, Protocol::Disconnect => 2,
Protocol::AddressExhausted => 3,
Protocol::Other(val) => val, Protocol::Other(val) => val,
} }
} }
@@ -30,6 +33,7 @@ impl Into<u8> for Protocol {
pub enum InErrorPacket<B> { pub enum InErrorPacket<B> {
TokenError, TokenError,
Disconnect, Disconnect,
AddressExhausted,
OtherError(ErrorPacket<B>), OtherError(ErrorPacket<B>),
} }
@@ -38,6 +42,7 @@ impl<B: AsRef<[u8]>> InErrorPacket<B> {
match Protocol::from(protocol) { match Protocol::from(protocol) {
Protocol::TokenError => Ok(InErrorPacket::TokenError), Protocol::TokenError => Ok(InErrorPacket::TokenError),
Protocol::Disconnect => Ok(InErrorPacket::Disconnect), Protocol::Disconnect => Ok(InErrorPacket::Disconnect),
Protocol::AddressExhausted => Ok(InErrorPacket::AddressExhausted),
Protocol::Other(_) => Ok(InErrorPacket::OtherError(ErrorPacket::new(buffer)?)), Protocol::Other(_) => Ok(InErrorPacket::OtherError(ErrorPacket::new(buffer)?)),
} }
} }