better style

This commit is contained in:
Daniella / Tove 2022-10-03 18:48:18 +02:00
parent f5caf49c92
commit c8074ef4b6

View file

@ -21,6 +21,7 @@ enum SafeReadWritePacket {
ResendRequest,
End,
}
use SafeReadWritePacket::*;
struct SafeReadWrite {
socket: UdpSocket,
@ -55,7 +56,7 @@ impl SafeReadWrite {
}
pub fn write_flush_safe(&mut self, buf: &[u8], flush: bool) -> Result<(), Error> {
self.internal_write_safe(buf, SafeReadWritePacket::Write, flush, false)
self.internal_write_safe(buf, Write, flush, false)
}
pub fn read_safe(&mut self, buf: &[u8]) -> Result<(Vec<u8>, usize), Error> {
@ -85,7 +86,7 @@ impl SafeReadWrite {
let id = u16::from_be_bytes([buf[0], buf[1]]);
if id <= self.packet_count_in as u16 {
self.socket
.send(&[buf[0], buf[1], SafeReadWritePacket::Ack as u8])
.send(&[buf[0], buf[1], Ack as u8])
.expect("send error");
}
if id == self.packet_count_in as u16 {
@ -109,10 +110,10 @@ impl SafeReadWrite {
// ask to resend, then do nothing
let id = (self.packet_count_in as u16).to_be_bytes();
self.socket
.send(&[id[0], id[1], SafeReadWritePacket::ResendRequest as u8])
.send(&[id[0], id[1], ResendRequest as u8])
.expect("send error");
}
if buf[2] == SafeReadWritePacket::End as u8 {
if buf[2] == End as u8 {
return Ok((vec![], 0));
}
}
@ -127,7 +128,7 @@ impl SafeReadWrite {
}
pub fn end(mut self) -> UdpSocket {
let _ = self.internal_write_safe(&mut [], SafeReadWritePacket::End, true, true);
let _ = self.internal_write_safe(&mut [], End, true, true);
self.socket
}
@ -190,7 +191,7 @@ impl SafeReadWrite {
if x != 3 {
continue;
}
if buf[2] == SafeReadWritePacket::Ack as u8 {
if buf[2] == Ack as u8 {
let n = u16::from_be_bytes([buf[0], buf[1]]);
self.last_transmitted.remove(&n);
if n == idn {
@ -202,7 +203,7 @@ impl SafeReadWrite {
// previous ones must be as well.
}
}
if buf[2] == SafeReadWritePacket::ResendRequest as u8 {
if buf[2] == ResendRequest as u8 {
let mut n = u16::from_be_bytes([buf[0], buf[1]]);
if !is_catching_up && !env::var("QFT_HIDE_DROPS").is_ok() {
println!("\r\x1b[KA packet dropped: {}", &n);