Skip to main content

Endpoint

Struct Endpoint 

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

Implementations§

Source§

impl Endpoint

Source

pub fn new(cfg: Arc<Config>, server: bool) -> Self

server enables accepting connections.

Source

pub fn config(&self) -> &Arc<Config> ⓘ

Source

pub fn len(&self) -> usize

Live connections.

Source

pub fn is_empty(&self) -> bool

Source

pub fn connect( &mut self, now: Instant, remote: SocketAddr, server_name: &str, token: &[u8], ) -> Result<ConnHandle, TransportError>

Starts a client connection.

Source

pub fn conn_mut(&mut self, h: ConnHandle) -> Option<&mut Connection>

Mutable access to a connection; it is scheduled for transmission.

Examples found in repository?
examples/bench_quic.rs (line 64)
53fn small(real: bool, n: usize, size: usize, conc: usize) -> f64 {
54    let (mut p, c, s) = pair(real);
55    let req = vec![7u8; size];
56    let mut buf = vec![0u8; 65536];
57    let mut open: Vec<(u64, usize)> = Vec::new(); // (stream, bytes received back)
58    let mut started = 0;
59    let mut done = 0;
60    let mut server_got: std::collections::HashMap<u64, usize> = Default::default();
61    let t = Instant::now();
62    while done < n {
63        while open.len() < conc && started < n {
64            let Ok(id) = p.client.conn_mut(c).unwrap().open_bi() else { break };
65            p.client.conn_mut(c).unwrap().stream_send(id, &req, true).unwrap();
66            open.push((id, 0));
67            started += 1;
68        }
69        p.step();
70        // Server: read requests, answer when complete.
71        while let Some(e) = p.server.poll_event(s) {
72            if let simoom_quic::Event::StreamReadable(id) = e {
73                let conn = p.server.conn_mut(s).unwrap();
74                while let Ok((k, fin)) = conn.stream_recv(id, &mut buf) {
75                    *server_got.entry(id).or_default() += k;
76                    if fin {
77                        server_got.remove(&id);
78                        conn.stream_send(id, &req, true).unwrap();
79                        break;
80                    }
81                    if k == 0 {
82                        break;
83                    }
84                }
85            }
86        }
87        while let Some(e) = p.client.poll_event(c) {
88            if let simoom_quic::Event::StreamReadable(id) = e {
89                let conn = p.client.conn_mut(c).unwrap();
90                while let Ok((k, fin)) = conn.stream_recv(id, &mut buf) {
91                    if let Some(o) = open.iter_mut().find(|o| o.0 == id) {
92                        o.1 += k;
93                    }
94                    if fin {
95                        open.retain(|o| o.0 != id);
96                        done += 1;
97                        break;
98                    }
99                    if k == 0 {
100                        break;
101                    }
102                }
103            }
104        }
105    }
106    let us = t.elapsed().as_secs_f64() * 1e6 / n as f64;
107    let pk = p.client.conn(c).unwrap().stats().sent_packets + p.server.conn(s).unwrap().stats().sent_packets;
108    eprintln!("    ({n} exchanges, {:.2} packets per exchange)", pk as f64 / n as f64);
109    us
110}
111
112/// One stream of `mb` MiB client to server; returns MB/s.
113fn bulk(real: bool, mb: usize) -> (f64, u64) {
114    let (mut p, c, s) = pair(real);
115    let chunk = vec![1u8; 256 << 10];
116    let total = mb << 20;
117    let id = p.client.conn_mut(c).unwrap().open_uni().unwrap();
118    let mut sent = 0;
119    let mut got = 0;
120    let mut buf = vec![0u8; 256 << 10];
121    let t = Instant::now();
122    while got < total {
123        if sent < total {
124            let conn = p.client.conn_mut(c).unwrap();
125            let want = (total - sent).min(chunk.len());
126            if let Ok(k) = conn.stream_send(id, &chunk[..want], sent + want == total) {
127                sent += k;
128            }
129        }
130        p.step();
131        if let Some(conn) = p.server.conn_mut(s) {
132            while let Ok((k, fin)) = conn.stream_recv(id, &mut buf) {
133                got += k;
134                if fin || k == 0 {
135                    break;
136                }
137            }
138        }
139        while p.server.poll_event(s).is_some() {}
140        while p.client.poll_event(c).is_some() {}
141    }
142    let secs = t.elapsed().as_secs_f64();
143    (total as f64 / secs / 1e6, p.client.conn(c).unwrap().stats().lost_packets)
144}
Source

pub fn conn(&self, h: ConnHandle) -> Option<&Connection>

Examples found in repository?
examples/bench_quic.rs (line 45)
32fn pair(real: bool) -> (Pair, ConnHandle, ConnHandle) {
33    let (cp, sp) = providers(real);
34    let mut c = Config::new(cp);
35    let mut s = Config::new(sp);
36    for x in [&mut c, &mut s] {
37        x.transport.max_data = 16 << 20;
38        x.transport.stream_window_bidi_local = 8 << 20;
39        x.transport.stream_window_bidi_remote = 8 << 20;
40        x.transport.send_buffer = 8 << 20;
41    }
42    let mut p = Pair::new(Arc::new(c), Arc::new(s), link(), 7);
43    p.batch = 16;
44    let ch = p.connect();
45    assert!(p.run_until(Duration::from_secs(10), |p| p.client.conn(ch).is_some_and(|c| c.is_established())
46        && p.server_conn().and_then(|s| p.server.conn(s)).is_some_and(|c| c.is_established())));
47    let sh = p.server_conn().unwrap();
48    p.run_for(Duration::from_millis(50));
49    (p, ch, sh)
50}
51
52/// `n` request/response exchanges of `size` bytes each way, `conc` in flight.
53fn small(real: bool, n: usize, size: usize, conc: usize) -> f64 {
54    let (mut p, c, s) = pair(real);
55    let req = vec![7u8; size];
56    let mut buf = vec![0u8; 65536];
57    let mut open: Vec<(u64, usize)> = Vec::new(); // (stream, bytes received back)
58    let mut started = 0;
59    let mut done = 0;
60    let mut server_got: std::collections::HashMap<u64, usize> = Default::default();
61    let t = Instant::now();
62    while done < n {
63        while open.len() < conc && started < n {
64            let Ok(id) = p.client.conn_mut(c).unwrap().open_bi() else { break };
65            p.client.conn_mut(c).unwrap().stream_send(id, &req, true).unwrap();
66            open.push((id, 0));
67            started += 1;
68        }
69        p.step();
70        // Server: read requests, answer when complete.
71        while let Some(e) = p.server.poll_event(s) {
72            if let simoom_quic::Event::StreamReadable(id) = e {
73                let conn = p.server.conn_mut(s).unwrap();
74                while let Ok((k, fin)) = conn.stream_recv(id, &mut buf) {
75                    *server_got.entry(id).or_default() += k;
76                    if fin {
77                        server_got.remove(&id);
78                        conn.stream_send(id, &req, true).unwrap();
79                        break;
80                    }
81                    if k == 0 {
82                        break;
83                    }
84                }
85            }
86        }
87        while let Some(e) = p.client.poll_event(c) {
88            if let simoom_quic::Event::StreamReadable(id) = e {
89                let conn = p.client.conn_mut(c).unwrap();
90                while let Ok((k, fin)) = conn.stream_recv(id, &mut buf) {
91                    if let Some(o) = open.iter_mut().find(|o| o.0 == id) {
92                        o.1 += k;
93                    }
94                    if fin {
95                        open.retain(|o| o.0 != id);
96                        done += 1;
97                        break;
98                    }
99                    if k == 0 {
100                        break;
101                    }
102                }
103            }
104        }
105    }
106    let us = t.elapsed().as_secs_f64() * 1e6 / n as f64;
107    let pk = p.client.conn(c).unwrap().stats().sent_packets + p.server.conn(s).unwrap().stats().sent_packets;
108    eprintln!("    ({n} exchanges, {:.2} packets per exchange)", pk as f64 / n as f64);
109    us
110}
111
112/// One stream of `mb` MiB client to server; returns MB/s.
113fn bulk(real: bool, mb: usize) -> (f64, u64) {
114    let (mut p, c, s) = pair(real);
115    let chunk = vec![1u8; 256 << 10];
116    let total = mb << 20;
117    let id = p.client.conn_mut(c).unwrap().open_uni().unwrap();
118    let mut sent = 0;
119    let mut got = 0;
120    let mut buf = vec![0u8; 256 << 10];
121    let t = Instant::now();
122    while got < total {
123        if sent < total {
124            let conn = p.client.conn_mut(c).unwrap();
125            let want = (total - sent).min(chunk.len());
126            if let Ok(k) = conn.stream_send(id, &chunk[..want], sent + want == total) {
127                sent += k;
128            }
129        }
130        p.step();
131        if let Some(conn) = p.server.conn_mut(s) {
132            while let Ok((k, fin)) = conn.stream_recv(id, &mut buf) {
133                got += k;
134                if fin || k == 0 {
135                    break;
136                }
137            }
138        }
139        while p.server.poll_event(s).is_some() {}
140        while p.client.poll_event(c).is_some() {}
141    }
142    let secs = t.elapsed().as_secs_f64();
143    (total as f64 / secs / 1e6, p.client.conn(c).unwrap().stats().lost_packets)
144}
Source

pub fn poll_event(&mut self, h: ConnHandle) -> Option<Event>

The next event of a connection. A drained connection is removed once its events have been read.

Examples found in repository?
examples/bench_quic.rs (line 71)
53fn small(real: bool, n: usize, size: usize, conc: usize) -> f64 {
54    let (mut p, c, s) = pair(real);
55    let req = vec![7u8; size];
56    let mut buf = vec![0u8; 65536];
57    let mut open: Vec<(u64, usize)> = Vec::new(); // (stream, bytes received back)
58    let mut started = 0;
59    let mut done = 0;
60    let mut server_got: std::collections::HashMap<u64, usize> = Default::default();
61    let t = Instant::now();
62    while done < n {
63        while open.len() < conc && started < n {
64            let Ok(id) = p.client.conn_mut(c).unwrap().open_bi() else { break };
65            p.client.conn_mut(c).unwrap().stream_send(id, &req, true).unwrap();
66            open.push((id, 0));
67            started += 1;
68        }
69        p.step();
70        // Server: read requests, answer when complete.
71        while let Some(e) = p.server.poll_event(s) {
72            if let simoom_quic::Event::StreamReadable(id) = e {
73                let conn = p.server.conn_mut(s).unwrap();
74                while let Ok((k, fin)) = conn.stream_recv(id, &mut buf) {
75                    *server_got.entry(id).or_default() += k;
76                    if fin {
77                        server_got.remove(&id);
78                        conn.stream_send(id, &req, true).unwrap();
79                        break;
80                    }
81                    if k == 0 {
82                        break;
83                    }
84                }
85            }
86        }
87        while let Some(e) = p.client.poll_event(c) {
88            if let simoom_quic::Event::StreamReadable(id) = e {
89                let conn = p.client.conn_mut(c).unwrap();
90                while let Ok((k, fin)) = conn.stream_recv(id, &mut buf) {
91                    if let Some(o) = open.iter_mut().find(|o| o.0 == id) {
92                        o.1 += k;
93                    }
94                    if fin {
95                        open.retain(|o| o.0 != id);
96                        done += 1;
97                        break;
98                    }
99                    if k == 0 {
100                        break;
101                    }
102                }
103            }
104        }
105    }
106    let us = t.elapsed().as_secs_f64() * 1e6 / n as f64;
107    let pk = p.client.conn(c).unwrap().stats().sent_packets + p.server.conn(s).unwrap().stats().sent_packets;
108    eprintln!("    ({n} exchanges, {:.2} packets per exchange)", pk as f64 / n as f64);
109    us
110}
111
112/// One stream of `mb` MiB client to server; returns MB/s.
113fn bulk(real: bool, mb: usize) -> (f64, u64) {
114    let (mut p, c, s) = pair(real);
115    let chunk = vec![1u8; 256 << 10];
116    let total = mb << 20;
117    let id = p.client.conn_mut(c).unwrap().open_uni().unwrap();
118    let mut sent = 0;
119    let mut got = 0;
120    let mut buf = vec![0u8; 256 << 10];
121    let t = Instant::now();
122    while got < total {
123        if sent < total {
124            let conn = p.client.conn_mut(c).unwrap();
125            let want = (total - sent).min(chunk.len());
126            if let Ok(k) = conn.stream_send(id, &chunk[..want], sent + want == total) {
127                sent += k;
128            }
129        }
130        p.step();
131        if let Some(conn) = p.server.conn_mut(s) {
132            while let Ok((k, fin)) = conn.stream_recv(id, &mut buf) {
133                got += k;
134                if fin || k == 0 {
135                    break;
136                }
137            }
138        }
139        while p.server.poll_event(s).is_some() {}
140        while p.client.poll_event(c).is_some() {}
141    }
142    let secs = t.elapsed().as_secs_f64();
143    (total as f64 / secs / 1e6, p.client.conn(c).unwrap().stats().lost_packets)
144}
Source

pub fn handles(&self) -> impl Iterator<Item = ConnHandle> + '_

Handles of all live connections.

Source

pub fn recv( &mut self, now: Instant, remote: SocketAddr, data: &mut [u8], response: &mut Vec<u8>, ) -> DatagramEvent

Processes a datagram from remote. Stateless replies are written to response.

Source

pub fn poll_transmit( &mut self, now: Instant, buf: &mut Vec<u8>, max_datagrams: usize, ) -> Option<(ConnHandle, Transmit)>

The next datagram batch to send from any connection.

Source

pub fn poll_timeout(&mut self) -> Option<Instant>

The earliest deadline over all connections.

Source

pub fn handle_timeout(&mut self, now: Instant, touched: &mut Vec<ConnHandle>)

Fires due timers; appends the affected connections to touched.

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 = !

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

fn try_from(value: U) -> Result<T, !>

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.