pub struct Endpoint { /* private fields */ }Implementations§
Source§impl Endpoint
impl Endpoint
pub fn config(&self) -> &Arc<Config> ⓘ
pub fn is_empty(&self) -> bool
Sourcepub fn connect(
&mut self,
now: Instant,
remote: SocketAddr,
server_name: &str,
token: &[u8],
) -> Result<ConnHandle, TransportError>
pub fn connect( &mut self, now: Instant, remote: SocketAddr, server_name: &str, token: &[u8], ) -> Result<ConnHandle, TransportError>
Starts a client connection.
Sourcepub fn conn_mut(&mut self, h: ConnHandle) -> Option<&mut Connection>
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}Sourcepub fn conn(&self, h: ConnHandle) -> Option<&Connection>
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}Sourcepub fn poll_event(&mut self, h: ConnHandle) -> Option<Event>
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}Sourcepub fn handles(&self) -> impl Iterator<Item = ConnHandle> + '_
pub fn handles(&self) -> impl Iterator<Item = ConnHandle> + '_
Handles of all live connections.
Sourcepub fn recv(
&mut self,
now: Instant,
remote: SocketAddr,
data: &mut [u8],
response: &mut Vec<u8>,
) -> DatagramEvent
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.
Sourcepub fn poll_transmit(
&mut self,
now: Instant,
buf: &mut Vec<u8>,
max_datagrams: usize,
) -> Option<(ConnHandle, Transmit)>
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.
Sourcepub fn poll_timeout(&mut self) -> Option<Instant>
pub fn poll_timeout(&mut self) -> Option<Instant>
The earliest deadline over all connections.
Sourcepub fn handle_timeout(&mut self, now: Instant, touched: &mut Vec<ConnHandle>)
pub fn handle_timeout(&mut self, now: Instant, touched: &mut Vec<ConnHandle>)
Fires due timers; appends the affected connections to touched.
Auto Trait Implementations§
impl !RefUnwindSafe for Endpoint
impl !Sync for Endpoint
impl !UnwindSafe for Endpoint
impl Forget for Endpoint
impl Freeze for Endpoint
impl Move for Endpoint
impl Send for Endpoint
impl Unpin for Endpoint
impl UnsafeUnpin for Endpoint
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more