Skip to main content

Timeout

Struct Timeout 

Source
pub struct Timeout { /* private fields */ }

Implementations§

Source§

impl Timeout

Source

pub fn new_same(timeout: u64, handles: i32) -> Timeout

Examples found in repository?
examples/m3u8_down.rs (line 87)
64    fn download(&mut self) -> Result<(), HlsError> {
65        self.req.set_url(self.index_url.as_str())?;
66        let body = self.req.send_check(Method::GET)?.text()?;
67        // println!("{}", body);
68        for line in body.split("\n") {
69            if line.starts_with("#EXT-X-MEDIA-SEQUENCE:") {
70                self.sequence = line.trim().replace("#EXT-X-MEDIA-SEQUENCE:", "").parse()?;
71                continue;
72            }
73            if line.starts_with("#EXT-X-KEY") {
74                let pos = line.find("URI=\"");
75                if let Some(pos) = pos {
76                    self.key_url = line[pos + 4..].trim().replace("\"", "");
77                }
78                if line.contains("=AES-128,") {
79                    self.cipher = Cipher::aes_128_cbc();
80                }
81                continue;
82            }
83            if line.starts_with("http") {
84                self.ts_urls.push(line.trim().to_string());
85            }
86        }
87        let mut timeout = Timeout::new_same(5000, 30000);
88        timeout.set_handle_times(10);
89        self.req.set_timeout(timeout);
90        if !self.key_url.is_empty() { self.get_key()?; }
91        self.down_ts()?;
92        Ok(())
93    }
Source

pub fn longer() -> Timeout

Examples found in repository?
examples/sync_h1.rs (line 18)
4fn main() {
5    let mut tss = 0;
6    for i in 0..100 {
7        let t = SystemTime::now().duration_since(SystemTime::UNIX_EPOCH).unwrap().as_millis();
8        println!("{}", t);
9        // let fingerprint = Fingerprint::from_hex_all("16030106b2010006ae0303f0aed3d4d9fac0e8d4ff98981a90257765d203b4ce089c591e86d8e7ec8ab90a204803c2150a14429bfe6536328fe11cfd4034264fa2a3a443c5972eeeb93d427100206a6a130113021303c02bc02fc02cc030cca9cca8c013c014009c009d002f0035010006453a3a000000230000001b0003020002ff010001000000000e000c0000093338686d7a672e636e0005000501000000000017000044cd00050003026832fe0d00ba00000100010900208e3fc249e1ce71ff4aefb0970b38167b6b7de98537b874130ba4e284e15f1c4f00909540fc3a77fcc8f96d51ff9144785ccf114d3618d9a77b0e88f54d4dd1279083483e0ad83a4f25e55951194048709bf0842651d940c291569b9cfe1323d6fc2d31348ccaaa7b79271fc41af0975d94f7a826819154e05f6f90bdaa4e2b215894ccd36f748ded2bcae0a61aa101a7187588c2b45b51d076356d0e47728974d6d1cdd2b3ce4a8e5e8f70a79fb8f288c868000b00020100002d00020101000a000c000a3a3a11ec001d00170018001200000010000e000c02683208687474702f312e31003304ef04ed3a3a00010011ec04c05b20439ba8b50e3a5800981889512ab253cd2f1ba1488613fbd79f43813c08e34ed45330a62991a6b37890d54d2d0c089251b146acace84512c031c74ac6a2ac6345b6668629aa143357b45921916de02ac5cc8d57e1ca9882ccad900640a1b51c587de3291a2f15ad67e180b79b442fe4606de978f7a27591a41ffcd91116c50703c45531999c9d377a173c249ef747a60a81158c0d3ef709b9b5a38af61b6b5c9740c343f7322b6510a60797cb39148ba310413b688354bb0b2e395dbf3935fd0a797d7b5e94acab23a95c163238dd1bc9b8b420599a0efd4726e85a0783fc8506436c3eb89ee96008b0c9c5a2047a2415bbb5a2768d7c8d58384644d5473de96721b24a3fc82ee68cc0a3a43cc73467ec515a3ac1a79b9070f4e4aad61ac50c7b4e9b125f66cba026807cdad5a43e4a5cfa2ac521801616bb58ea068689c15afd4592b26545c3a8c638800a3429c32237a902f1a605458935391c4d352a211cb2122203f9ea38e3d44b29741502bb57c7850ffaf36ab0db72ac9c0fc0ba309661096bc550d86b442beca080c0602e02a54ed2171e58b0b82582c568a5b1407d8d35448cf907a43575aed4c5371595d1456f29778c892325d4d785a3a384a30b838e6b0d59990ca54ba52369c4faf835a2f50cbd504f7d38cdc4047bf7acae92090cf121180096a513dc4cadf290641ab6e4375aa477395b8902b74c39e62b945a09438d83b1d41ac2f204c4614425bed86e221c60c8520e1c3233e5ccb53c228c0d525fb7823d9d9c4337e36785eb61590794f9565b3dd2722a2834b536be157a307d928d7f910167a314b8705bdddc1b4c9c139a5320380910b1263b40a6c6065c84266a2c036a19d3a51f5edbb8eaf3cb1e8295ef1ab978f5306da9b11a5a3df473bbd2acca084a4c4bba0bc478630283b0e6910bde3052c6f58300703a6e9524381b4cc1b247236acc1c0bae6cb69c463c29811b04d93a589ba36d30c9b4d1fb234368a9b3e94abaf419a220af730917488bc9be585f7111c9a13a8544969bf3e397b1f2ceba0ca7f21785531a3f7856248f54a5bd854124b21e1e75c366e8b5293130bdb902db0a05e9803c3d7827d5cc26046815102c3713b4a14ef63aed3163319244995a6524dbabfaf93ed8a95e08641377683dd6b3b05084bf48f77d47904d09656d4a19b457d84bcfd77a4c433393bbb43f09931cf4896cf891990c9363202467b6193ea6b8bd493733235c93c118feb808b1d9b38cc7862c744342e2baeeec6299d0a21898aa9576ae61b2703a5b072521166f6693aa4b5e6148ad4e7c21a21a7972a0c8c3f986e95392ed2b15e51a5f2e5b90e4766320513e3bfa4d67688fb6c547147c47aa71c04095336b11b32b52a6c9d047a1357eece2688efb2045184653a480ef15a3fb8c4851d8c0407b24a87b55fd36af59b18fff38b183b6256e15c161395a46f62ce1b0af240319dec84d3aa04e2773ac289b393160683e901b2b622d615b2719b06cc12bae79fca101e737a91434c8e0828cc6a71b740216964a06a9952d9c54f24743b1b9c4fc9475554aa8a87719ccd7ae40374c87d8018937c7b6007e028b348e884d201087416396ec3237b61319e0f40e436a6a1dc75f2486a68c60c27f719d251a9d73b3de3bd91858d3f3d4043384f7ad42422b47b96bdd03b5556f8107232953dad801970157aa95971638e2908d55001d0020552cb65392fdab1ff61dd3b43c895fdf782c61bb6f05519f2b7d9e28facfd25e000d0012001004030804040105030805050108060601002b000706dada030403031a1a0001001603030046100000424104ff635373fbbfbc37444a2026372f57fd06c5205bacfe32b61261a9d29bf1fca57f91ef22cb2ba46af8cf9ae7c3123f56634099af297dcd30835cd81664005fb9140303000101").unwrap();
10        // let fingerprint = Fingerprint::from_ja3("771,4865-4866-4867-49195-49199-49196-49200-52393-52392-49171-49172-156-157-47-53,0-23-65281-10-11-35-16-5-13-18-51-45-43-27-17513-21,29-23-24,0", "4b107bbnbc-01o-3781k7bbnbc-01v25461k").unwrap();
11        // let certs = Certificate::from_pem_file("/home/xl/1/client.crt").unwrap();
12        // let key = RsaKey::from_pri_pem_file("/home/xl/1/client.key").unwrap();
13        let mut req = ScReq::new()
14            // .with_fingerprint(fingerprint)
15            .with_alpn(ALPN::Http20)
16            // .with_mtls(certs, key)
17            .with_verify(false)
18            .with_timeout(Timeout::longer())
19            // .with_proxy(Proxy::new_http_plain("127.0.0.1", 10280))
20            ;
21        let headers = json::object! {
22            "User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/120.0.0.0 Safari/537.36 Edg/120.0.0.0",
23            "Accept": "*/*",
24            "Sec-Fetch-Site": "none",
25            "Sec-Fetch-Mode": "navigate",
26            "Sec-Fetch-Dest": "document",
27            "sec-fetch-user":"?1",
28            "upgrade-insecure-requests":"1",
29            "sec-ch-ua": "\"Not_A Brand\";v=\"8\", \"Chromium\";v=\"120\", \"Microsoft Edge\";v=\"120\"",
30            "sec-ch-ua-mobile": "?0",
31            "sec-ch-ua-platform": "\"Windows\"",
32            "Accept-Language": "zh-CN,zh;q=0.9",
33            "Accept-Encoding": "gzip,deflate,br,zstd",
34            "Cache-Control": "no-cache",
35            "Connection": "keep-alive",
36
37        };
38        // req.set_url("https://zhifazhe.top").unwrap();
39        // req.set_url("http://3434.characlink.com").unwrap();
40        // req.set_url("https://m.so.com").unwrap();
41        // req.set_proxy(Proxy::new_socks5("34.124.190.108", 8080));
42        // println!("{}", et - t);
43        // req.set_url("https://ms.xllgl.top").unwrap();
44        req.set_url("https://www.baidu.com").unwrap();
45
46        // req.set_url("https://jetstar.com").unwrap();
47        // let et = SystemTime::now().duration_since(SystemTime::UNIX_EPOCH).unwrap().as_millis();
48        // println!("{}", et - t);
49        // req.set_url("https://cn.bing.com/search?q=site%EF%BC%9Aqq.com&first=150&FORM=PERE2").unwrap();
50        // req.set_url("https://accounts.pcid.ca/login").unwrap();
51        // req.set_url("https://ccppdd.zzzzzzyyyyy.shop/api/v1/client/s9FkyFPBngt80pFn1?token=a0cedb7c6645280ec2402db62d550a17").unwrap();
52        // req.set_url("https://www.link114.cn/").unwrap();
53        // req.set_url("https://127.0.0.1:8000").unwrap();
54        // req.set_url("http://zwfw.hubei.gov.cn/web/user/uias_login.do?appCode=hbzwfw&gotoUrl=http%3A%2F%2Fzwfw.hubei.gov.cn%2Fwebview%2Fgrkj%2Fwelcome.html&p01=").unwrap();
55        req.set_auto_redirect(true);
56        req.set_headers_json(headers).unwrap();
57        // println!("6");
58        let res = req.get().unwrap();
59        let et = SystemTime::now().duration_since(SystemTime::UNIX_EPOCH).unwrap().as_millis();
60        tss += et - t;
61        println!("{}", et - t);
62        // res.text().unwrap();
63        // println!("{}", res.header());
64        // println!("{}", res.text().unwrap().len());
65        // for _ in 0..50 {
66        //     let resp = req.get().unwrap();
67        //     // let body = res.decode_body().unwrap().as_string().unwrap();
68        //     // println!("{}", resp.header().status());
69        //     // println!("{}", resp.text().unwrap().len());
70        //     let et = SystemTime::now().duration_since(SystemTime::UNIX_EPOCH).unwrap().as_millis();
71        //     println!("{}", et - t);
72        // }
73
74
75        // break;
76    }
77    println!("{}", tss / 100);
78}
Source

pub fn is_peer_closed(&self, status: impl AsRef<str>) -> bool

Source

pub fn connect(&self) -> Duration

Source

pub fn read(&self) -> Duration

Source

pub fn write(&self) -> Duration

Source

pub fn handle(&self) -> Duration

Source

pub fn connect_times(&self) -> i32

Source

pub fn handle_times(&self) -> i32

Source

pub fn set_connect(&mut self, millis: u64)

Source

pub fn set_read(&mut self, millis: u64)

Source

pub fn set_write(&mut self, millis: u64)

Source

pub fn set_handle(&mut self, millis: u64)

Source

pub fn set_connect_times(&mut self, connect_times: i32)

Source

pub fn set_handle_times(&mut self, handle_times: i32)

Examples found in repository?
examples/m3u8_down.rs (line 88)
64    fn download(&mut self) -> Result<(), HlsError> {
65        self.req.set_url(self.index_url.as_str())?;
66        let body = self.req.send_check(Method::GET)?.text()?;
67        // println!("{}", body);
68        for line in body.split("\n") {
69            if line.starts_with("#EXT-X-MEDIA-SEQUENCE:") {
70                self.sequence = line.trim().replace("#EXT-X-MEDIA-SEQUENCE:", "").parse()?;
71                continue;
72            }
73            if line.starts_with("#EXT-X-KEY") {
74                let pos = line.find("URI=\"");
75                if let Some(pos) = pos {
76                    self.key_url = line[pos + 4..].trim().replace("\"", "");
77                }
78                if line.contains("=AES-128,") {
79                    self.cipher = Cipher::aes_128_cbc();
80                }
81                continue;
82            }
83            if line.starts_with("http") {
84                self.ts_urls.push(line.trim().to_string());
85            }
86        }
87        let mut timeout = Timeout::new_same(5000, 30000);
88        timeout.set_handle_times(10);
89        self.req.set_timeout(timeout);
90        if !self.key_url.is_empty() { self.get_key()?; }
91        self.down_ts()?;
92        Ok(())
93    }

Trait Implementations§

Source§

impl Default for Timeout

Source§

fn default() -> Self

Returns the “default value” for a type. Read more
Source§

impl TryFrom<JsonValue> for Timeout

Source§

type Error = HlsError

The type returned in the event of a conversion error.
Source§

fn try_from(value: JsonValue) -> Result<Self, Self::Error>

Performs the conversion.

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.