Skip to content

Commit c938d71

Browse files
authored
Merge pull request #4 from dani-garcia/tokio03
Update to Tokio 0.3
2 parents 0d87d2d + 5ecdb65 commit c938d71

File tree

7 files changed

+33
-35
lines changed

7 files changed

+33
-35
lines changed

Cargo.toml

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "async_ftp"
3-
version = "4.0.4"
3+
version = "5.0.0"
44
authors = ["Daniel García <[email protected]>", "Matt McCoy <[email protected]>"]
55
documentation = "https://docs.rs/async_ftp/"
66
repository = "https://github.com/dani-garcia/rust_async_ftp"
@@ -26,10 +26,11 @@ lazy_static = "1.4.0"
2626
regex = "1.3.9"
2727
chrono = "0.4.11"
2828

29-
tokio = { version = "0.2.21", features = ["tcp", "dns", "io-util"] }
30-
tokio-rustls = { version = "0.13.1", optional = true }
31-
pin-project = "0.4.17"
29+
tokio = { version = "1.0.1", features = ["net", "io-util"] }
30+
tokio-rustls = { version = "0.22.0", optional = true }
31+
pin-project = "1.0.0"
3232

33-
[dev-dependencies.tokio]
34-
version = "0.2.21"
35-
features = [ "macros", "stream", "io-util" ]
33+
[dev-dependencies]
34+
tokio = { version = "1.0.1", features = ["macros", "rt"] }
35+
tokio-util = { version = "0.6.0", features = ["io"] }
36+
tokio-stream = "0.1.0"

examples/connecting.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ async fn test_ftp(addr: &str, user: &str, pass: &str) -> Result<(), FtpError> {
2626
fn main() {
2727
let future = test_ftp("172.25.82.139", "anonymous", "[email protected]");
2828

29-
tokio::runtime::Builder::new()
29+
tokio::runtime::Builder::new_current_thread()
3030
.enable_all()
3131
.build()
3232
.unwrap()

src/data_stream.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
use std::io;
22
use std::pin::Pin;
33
use std::task::{Context, Poll};
4-
use tokio::io::{AsyncRead, AsyncWrite};
4+
use tokio::io::{AsyncRead, AsyncWrite, ReadBuf};
55
use tokio::net::TcpStream;
66
#[cfg(feature = "secure")]
77
use tokio_rustls::client::TlsStream;
@@ -47,8 +47,8 @@ impl AsyncRead for DataStream {
4747
fn poll_read(
4848
self: Pin<&mut Self>,
4949
cx: &mut Context<'_>,
50-
buf: &mut [u8],
51-
) -> Poll<io::Result<usize>> {
50+
buf: &mut ReadBuf<'_>,
51+
) -> Poll<io::Result<()>> {
5252
match self.project() {
5353
DataStreamProj::Tcp(stream) => stream.poll_read(cx, buf),
5454
#[cfg(feature = "secure")]

src/ftp.rs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -617,11 +617,12 @@ impl FtpStream {
617617
#[cfg(test)]
618618
mod tests {
619619
use super::FtpStream;
620-
use tokio::{io::stream_reader, stream};
620+
use tokio_stream::once;
621+
use tokio_util::io::StreamReader;
621622

622623
#[tokio::test]
623624
async fn list_command_dos_newlines() {
624-
let data_stream = stream_reader(stream::once(Ok(
625+
let data_stream = StreamReader::new(once(Ok::<_, std::io::Error>(
625626
b"Hello\r\nWorld\r\n\r\nBe\r\nHappy\r\n" as &[u8]
626627
)));
627628

@@ -636,7 +637,7 @@ mod tests {
636637

637638
#[tokio::test]
638639
async fn list_command_unix_newlines() {
639-
let data_stream = stream_reader(stream::once(Ok(b"Hello\nWorld\n\nBe\nHappy\n" as &[u8])));
640+
let data_stream = StreamReader::new(once(Ok::<_, std::io::Error>(b"Hello\nWorld\n\nBe\nHappy\n" as &[u8])));
640641

641642
assert_eq!(
642643
FtpStream::get_lines_from_stream(data_stream).await.unwrap(),

tests/Dockerfile

Lines changed: 10 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,14 @@
1-
FROM i386/ubuntu:latest
1+
FROM ubuntu:latest
22

3-
RUN apt-get update -qq &&\
4-
apt-get install -yqq vsftpd
3+
RUN apt update && apt install -y vsftpd
54

6-
RUN mkdir -p /var/run/vsftpd/empty &&\
7-
useradd -s /bin/bash -d /home/ftp -m -c "Doe ftp user" -g ftp Doe &&\
8-
echo "Doe:mumble"| chpasswd &&\
9-
echo "listen=yes\n\
10-
anon_root=/home/ftp\n\
11-
local_enable=yes\n\
12-
local_umask=022\n\
13-
pasv_enable=YES\n\
14-
pasv_min_port=65000\n\
15-
pasv_max_port=65010\n\
16-
write_enable=yes\n\
17-
log_ftp_protocol=yes" > /etc/vsftpd.conf &&\
18-
echo "/etc/init.d/vsftpd start" | tee -a /etc/bash.bashrc
5+
RUN useradd --home-dir /home/ftp --create-home --groups ftp Doe
6+
RUN echo "Doe:mumble" | chpasswd
7+
8+
RUN cp /etc/vsftpd.conf /etc/vsftpd.conf.orig
9+
RUN echo "write_enable=yes\nlog_ftp_protocol=yes" > /etc/vsftpd.conf
10+
RUN cat /etc/vsftpd.conf.orig >> /etc/vsftpd.conf
11+
12+
RUN echo "/etc/init.d/vsftpd start" | tee -a /etc/bash.bashrc
1913

2014
CMD ["/bin/bash"]

tests/ftp-server.sh

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
#!/bin/sh
22

3-
# run the ftp server instance in detached mode (in the background)
4-
# but also with TTY and interactive mode, so we can attach to it if we want to
5-
docker run -dti --privileged -p 21:21 -p 65000-65010:65000-65010 ftp-server
3+
# Build the docker image
4+
docker build -t ftp-server .
5+
6+
# run the ftp server instance
7+
docker run --rm --name ftp-server -ti --net=host ftp-server

tests/lib.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ use std::io::Cursor;
55
#[test]
66
fn test_ftp() {
77
let future = async {
8-
let mut ftp_stream = FtpStream::connect("172.25.82.139:21").await?;
8+
let mut ftp_stream = FtpStream::connect("192.168.1.60:21").await?;
99
let _ = ftp_stream.login("Doe", "mumble").await?;
1010

1111
ftp_stream.mkdir("test_dir").await?;
@@ -36,7 +36,7 @@ fn test_ftp() {
3636
Ok(())
3737
};
3838

39-
let result: Result<(), FtpError> = tokio::runtime::Builder::new()
39+
let result: Result<(), FtpError> = tokio::runtime::Builder::new_current_thread()
4040
.enable_all()
4141
.build()
4242
.unwrap()

0 commit comments

Comments
 (0)