Skip to content

Commit a953356

Browse files
committed
Upgrade to the v1 of smol building blocks
1 parent 69daed8 commit a953356

File tree

4 files changed

+65
-44
lines changed

4 files changed

+65
-44
lines changed

CHANGELOG.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,12 @@ All notable changes to this project will be documented in this file.
55
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
66
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
77

8+
## [Unreleased]
9+
10+
### Changed
11+
12+
- Upgrade to the v1 of [smol] building blocks.
13+
814
## [0.3.2] - 2020-08-31
915

1016
### Changed

Cargo.toml

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -22,11 +22,11 @@ num-derive = "0.3.2"
2222
num-traits = "0.2.12"
2323
log = "0.4.11"
2424

25-
async-io = "0.2.6"
26-
async-mutex = "1.2.0"
2725
async-trait = "0.1.40"
28-
blocking = "0.6.1"
29-
futures-lite = "1.0.0"
26+
async-io = "1.0.2"
27+
async-mutex = "1.3.0"
28+
blocking = "1.0.0"
29+
futures-lite = "1.4.0"
3030
futures-util = { version = "0.3.5", default-features = false, features = ["alloc"] }
3131

3232
[dev-dependencies]
@@ -36,8 +36,8 @@ rand = { version = "0.7.3", features = ["small_rng"] }
3636
md5 = "0.7.0"
3737
tempfile = "3.1.0"
3838
fern = "0.6.0"
39-
async-executor = "0.2.1"
40-
async-channel = "1.4.1"
39+
async-executor = "1.1.1"
40+
async-channel = "1.4.2"
4141

4242
# deps for tftpd-targz.rs
4343
async-std = "1.6.3"

src/tests/rrq.rs

Lines changed: 47 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -3,43 +3,59 @@
33

44
use async_executor::Executor;
55
use blocking::Unblock;
6+
use futures_lite::future::block_on;
7+
use std::cell::Cell;
8+
use std::rc::Rc;
9+
use std::sync::Arc;
610

711
use super::external_client::*;
812
use super::handlers::*;
913
use crate::server::TftpServerBuilder;
1014

1115
fn transfer(file_size: usize, block_size: Option<u16>) {
12-
let ex = Executor::new();
13-
14-
ex.run(async {
15-
let (md5_tx, md5_rx) = async_channel::bounded(1);
16-
let handler = RandomHandler::new(file_size, md5_tx);
17-
18-
// bind
19-
let tftpd = TftpServerBuilder::with_handler(handler)
20-
.bind("127.0.0.1:0".parse().unwrap())
21-
.build()
22-
.await
23-
.unwrap();
24-
let addr = tftpd.listen_addr().unwrap();
25-
26-
// start client
27-
let mut tftp_recv = Unblock::new(());
28-
let tftp_recv = tftp_recv
29-
.with_mut(move |_| external_tftp_recv("test", addr, block_size));
30-
31-
// start server
32-
ex.spawn(async move {
33-
tftpd.serve().await.unwrap();
34-
})
35-
.detach();
36-
37-
// check md5
38-
let client_md5 = tftp_recv.await.expect("failed to run tftp client");
39-
let server_md5 =
40-
md5_rx.recv().await.expect("failed to receive server md5");
41-
assert_eq!(client_md5, server_md5);
42-
});
16+
let ex = Arc::new(Executor::new());
17+
let transfered = Rc::new(Cell::new(false));
18+
19+
block_on(ex.run({
20+
let ex = ex.clone();
21+
let transfered = transfered.clone();
22+
23+
async move {
24+
let (md5_tx, md5_rx) = async_channel::bounded(1);
25+
let handler = RandomHandler::new(file_size, md5_tx);
26+
27+
// bind
28+
let tftpd = TftpServerBuilder::with_handler(handler)
29+
.bind("127.0.0.1:0".parse().unwrap())
30+
.build()
31+
.await
32+
.unwrap();
33+
let addr = tftpd.listen_addr().unwrap();
34+
35+
// start client
36+
let mut tftp_recv = Unblock::new(());
37+
let tftp_recv = tftp_recv.with_mut(move |_| {
38+
external_tftp_recv("test", addr, block_size)
39+
});
40+
41+
// start server
42+
ex.spawn(async move {
43+
tftpd.serve().await.unwrap();
44+
})
45+
.detach();
46+
47+
// check md5
48+
let client_md5 =
49+
tftp_recv.await.expect("failed to run tftp client");
50+
let server_md5 =
51+
md5_rx.recv().await.expect("failed to receive server md5");
52+
assert_eq!(client_md5, server_md5);
53+
54+
transfered.set(true);
55+
}
56+
}));
57+
58+
assert!(transfered.get());
4359
}
4460

4561
#[test]

src/utils.rs

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
use async_io::Timer;
2-
use futures_util::future::{select, Either};
2+
use futures_lite::future;
33
use std::future::Future;
44
use std::io;
55
use std::time::Duration;
@@ -8,10 +8,9 @@ pub async fn io_timeout<T>(
88
dur: Duration,
99
f: impl Future<Output = io::Result<T>>,
1010
) -> io::Result<T> {
11-
futures_lite::pin!(f);
12-
13-
match select(f, Timer::after(dur)).await {
14-
Either::Left((out, _)) => out,
15-
Either::Right(_) => Err(io::ErrorKind::TimedOut.into()),
16-
}
11+
future::race(f, async move {
12+
Timer::after(dur).await;
13+
Err(io::ErrorKind::TimedOut.into())
14+
})
15+
.await
1716
}

0 commit comments

Comments
 (0)