Compare commits

..

No commits in common. "9ea54102aff385c782fd6f46d7a5d71e6f756b72" and "401fd144cd666b595cd343cfc7cb45940c1eae08" have entirely different histories.

2 changed files with 7 additions and 20 deletions

View file

@ -277,12 +277,6 @@ impl AccessorySocket {
Ok(packet)
}
async fn reconnect(&mut self) -> Result<TcpStream, std::io::Error> {
self.socket.flush().await?;
self.socket.shutdown().await?;
TcpStream::connect(format!("{}:{}", self.ip, self.port)).await
}
async fn get_next(&mut self) -> Result<Vec<u8>, HomekitError> {
// max packet size + authtag size + associated data size
let mut buf = [0; 1024 + 16 + 2];
@ -292,26 +286,19 @@ impl AccessorySocket {
while read_num == 0 {
if tries > 20 {
log::error!("reconnect unsuccessful");
log::error!("unsuccessfully tried to reconnect");
return Err(ConnectionError::Http.into());
}
tries += 1;
log::info!("read 0 bytes - about to reconnect");
std::thread::sleep(std::time::Duration::from_millis(200));
self.socket.flush().await?;
match tokio::time::timeout(Duration::from_secs(5), self.reconnect()).await {
Ok(Ok(socket)) => self.socket = socket,
_ => continue,
}
log::warn!("reconnecting...");
self.socket = TcpStream::connect(format!("{}:{}", self.ip, self.port)).await?;
read_num =
match tokio::time::timeout(Duration::from_secs(5), self.socket.read(&mut buf)).await
{
Ok(Ok(val)) => val,
_ => continue,
}
read_num = self.socket.read(&mut buf).await?;
}
if let Some(encryption) = self.socket_encryption.as_mut() {
let associated_data: [u8; 2] = buf[..2].try_into()?;
let length = u16::from_le_bytes(associated_data);

View file

@ -686,7 +686,7 @@ impl From<CharacteristicTypeInner> for CharacteristicType {
fn from(value: CharacteristicTypeInner) -> Self {
match value {
CharacteristicTypeInner::Unknown(v) => {
log::info!("unknown characteristic type: {v}");
log::warn!("unknown characteristic type: {v}");
Self::Unknown
}
CharacteristicTypeInner::AccessControlLevel => Self::AccessControlLevel,
@ -1206,7 +1206,7 @@ impl From<ServiceTypeInner> for ServiceType {
fn from(value: ServiceTypeInner) -> Self {
match value {
ServiceTypeInner::Unknown(v) => {
log::info!("unknown service type: {v}");
log::warn!("unknown service type: {v}");
Self::Unknown
}
ServiceTypeInner::AccessControl => Self::AccessControl,