use std::time::Duration;
use clean_text::one_line;
use crate::text::ARROW;
#[derive(Debug, Clone)]
pub struct SlotMeta {
pub host: String,
pub nth: u16,
}
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum SlotState {
Idle,
Fast,
Probe,
Cruise,
Cool { wait: Duration },
Recover,
Dead { code: u16 },
}
#[derive(Debug, Clone, Copy)]
pub struct SlotRow {
pub slot: usize,
pub in_flight: u16,
pub cwnd: u16,
pub state: SlotState,
pub tok: u64,
}
#[derive(Debug, Clone, Copy, Default)]
pub struct PoolStat {
pub in_flight: u16,
pub cap: u16,
pub queued: usize,
pub tok: u64,
}
#[derive(Clone)]
pub(crate) struct Name {
tag: String,
from_n: usize,
}
impl Name {
pub(crate) fn new(from: &str, out: &str) -> Self {
let from = one_line(from);
let out = one_line(out);
let mut tag = String::with_capacity(from.len() + ARROW.len() + out.len());
tag.push_str(&from);
tag.push_str(ARROW);
tag.push_str(&out);
Self {
tag,
from_n: from.len(),
}
}
#[inline]
pub(crate) fn tag(&self) -> &str {
&self.tag
}
#[inline]
pub(crate) fn from(&self) -> &str {
unsafe { self.tag.get_unchecked(..self.from_n) }
}
#[inline]
pub(crate) fn out(&self) -> &str {
unsafe { self.tag.get_unchecked(self.from_n + ARROW.len()..) }
}
}
pub(crate) enum Event {
ScanFound(usize),
ScanChecked { checked: usize, cache: usize },
Plan { job: usize, cache: usize },
Pool(Vec<SlotMeta>),
Slot { row: SlotRow, stat: PoolStat },
Hit,
Grow,
Skip,
Fail,
Change,
Start { id: u32, name: Name },
JobSlot { id: u32, slot: usize },
JobTok { id: u32, tok: u32 },
Text { id: u32, text: String, reply: bool },
Retry {
id: u32,
nth: usize,
total: usize,
wait: Duration,
base: String,
err: String,
},
End {
id: u32,
err: Option<String>,
active: Duration,
},
Log(String),
Close,
}