|
| 1 | +use bytes::Bytes; |
1 | 2 | use quinn::Connection; |
2 | 3 |
|
3 | 4 | async fn open_bidirectional_stream(connection: Connection) -> anyhow::Result<()> { |
4 | | - let (mut send, recv) = connection.open_bi().await?; |
| 5 | + let (mut send, mut recv) = connection.open_bi().await?; |
5 | 6 | send.write_all(b"test").await?; |
6 | | - send.finish().await?; |
| 7 | + send.finish()?; |
7 | 8 | let received = recv.read_to_end(10).await?; |
8 | 9 | Ok(()) |
9 | 10 | } |
10 | 11 |
|
11 | 12 | async fn receive_bidirectional_stream(connection: Connection) -> anyhow::Result<()> { |
12 | | - while let Ok((mut send, recv)) = connection.accept_bi().await { |
| 13 | + while let Ok((mut send, mut recv)) = connection.accept_bi().await { |
13 | 14 | // Because it is a bidirectional stream, we can both send and receive. |
14 | 15 | println!("request: {:?}", recv.read_to_end(50).await?); |
15 | 16 | send.write_all(b"response").await?; |
16 | | - send.finish().await?; |
| 17 | + send.finish()?; |
17 | 18 | } |
18 | 19 | Ok(()) |
19 | 20 | } |
20 | 21 |
|
21 | 22 | async fn open_unidirectional_stream(connection: Connection) -> anyhow::Result<()> { |
22 | 23 | let mut send = connection.open_uni().await?; |
23 | 24 | send.write_all(b"test").await?; |
24 | | - send.finish().await?; |
| 25 | + send.finish()?; |
25 | 26 | Ok(()) |
26 | 27 | } |
27 | 28 |
|
28 | 29 | async fn receive_unidirectional_stream(connection: Connection) -> anyhow::Result<()> { |
29 | | - while let Ok(recv) = connection.accept_uni().await { |
| 30 | + while let Ok(mut recv) = connection.accept_uni().await { |
30 | 31 | // Because it is a unidirectional stream, we can only receive not send back. |
31 | 32 | println!("{:?}", recv.read_to_end(50).await?); |
32 | 33 | } |
33 | 34 | Ok(()) |
34 | 35 | } |
35 | 36 |
|
36 | 37 | async fn send_unreliable(connection: Connection) -> anyhow::Result<()> { |
37 | | - connection.send_datagram(b"test".into()).await?; |
| 38 | + connection.send_datagram(Bytes::from(&b"test"[..]))?; |
38 | 39 | Ok(()) |
39 | 40 | } |
40 | 41 |
|
|
0 commit comments