ctf_pwn/io/util/timeout/
async_read_cache_timeout_ext.rs

1use crate::io::util::timeout::read_until_timeout::{read_until_timeout, ReadUntilTimeout};
2use crate::io::{read_until_regex_timeout, AsyncCacheRead, ReadUntilRegexTimeout};
3use std::time::Duration;
4
5pub trait AsyncReadCacheTimeoutExt: AsyncCacheRead {
6    fn read_until_timeout<'a, T: AsRef<[u8]>>(
7        &'a mut self,
8        delim: T,
9        buf: &'a mut Vec<u8>,
10        timeout: Duration,
11    ) -> ReadUntilTimeout<'a, Self, T>
12    where
13        Self: Unpin,
14    {
15        read_until_timeout(self, delim, buf, timeout)
16    }
17
18    fn read_until_regex_timeout<'a>(
19        &'a mut self,
20        pattern: &str,
21        buf: &'a mut Vec<u8>,
22        timeout: Duration,
23    ) -> Result<ReadUntilRegexTimeout<'a, Self>, regex::Error>
24    where
25        Self: Unpin,
26    {
27        read_until_regex_timeout(self, pattern, buf, timeout)
28    }
29
30    fn read_line_timeout<'a>(
31        &'a mut self,
32        buf: &'a mut Vec<u8>,
33        timeout: Duration,
34    ) -> ReadUntilTimeout<'a, Self, &'static [u8]>
35    where
36        Self: Unpin,
37    {
38        read_until_timeout(self, b"\n", buf, timeout)
39    }
40
41    fn read_line_crlf_timeout<'a>(
42        &'a mut self,
43        buf: &'a mut Vec<u8>,
44        timeout: Duration,
45    ) -> ReadUntilTimeout<'a, Self, &'static [u8]>
46    where
47        Self: Unpin,
48    {
49        read_until_timeout(self, b"\r\n", buf, timeout)
50    }
51}
52
53impl<R: AsyncCacheRead + ?Sized> AsyncReadCacheTimeoutExt for R {}