Skip to content

Commit 415e690

Browse files
authored
Merge pull request #27 from messense/tokio-0-3
Upgrade tokio to 0.3
2 parents 002a16d + 1b46320 commit 415e690

File tree

6 files changed

+24
-37
lines changed

6 files changed

+24
-37
lines changed

Cargo.toml

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,12 +24,11 @@ required-features = ["tor"]
2424

2525
[dependencies]
2626
futures = "0.3"
27-
tokio = { version="0.2", features = ["io-util", "stream", "tcp"] }
28-
bytes = "0.4"
27+
tokio = { version = "0.3", features = ["io-util", "net"] }
2928
either = "1"
3029
thiserror = "1.0"
3130

3231
[dev-dependencies]
33-
tokio = { version = "0.2", features = ["io-util", "rt-threaded", "uds", "dns"] }
32+
tokio = { version = "0.3", features = ["io-util", "rt-multi-thread", "net"] }
3433
once_cell = "1.2.0"
3534
hyper = "0.13"

src/tcp.rs

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ use std::{
1414
pin::Pin,
1515
};
1616
use tokio::{
17-
io::{AsyncRead, AsyncReadExt, AsyncWrite, AsyncWriteExt},
17+
io::{AsyncRead, AsyncReadExt, AsyncWrite, AsyncWriteExt, ReadBuf},
1818
net::TcpStream,
1919
};
2020

@@ -671,11 +671,7 @@ where S: AsyncRead + AsyncWrite + Unpin
671671
impl<T> AsyncRead for Socks5Stream<T>
672672
where T: AsyncRead + Unpin
673673
{
674-
unsafe fn prepare_uninitialized_buffer(&self, buf: &mut [std::mem::MaybeUninit<u8>]) -> bool {
675-
AsyncRead::prepare_uninitialized_buffer(&self.socket, buf)
676-
}
677-
678-
fn poll_read(mut self: Pin<&mut Self>, cx: &mut Context<'_>, buf: &mut [u8]) -> Poll<io::Result<usize>> {
674+
fn poll_read(mut self: Pin<&mut Self>, cx: &mut Context<'_>, buf: &mut ReadBuf<'_>) -> Poll<io::Result<()>> {
679675
AsyncRead::poll_read(Pin::new(&mut self.socket), cx, buf)
680676
}
681677
}

tests/common.rs

Lines changed: 8 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
use futures::{future, StreamExt};
21
use once_cell::sync::OnceCell;
32
use std::{
43
io::{Read, Write},
@@ -22,21 +21,14 @@ pub const ECHO_SERVER_ADDR: &'static str = "localhost:10007";
2221
pub const MSG: &[u8] = b"hello";
2322

2423
pub async fn echo_server() -> Result<()> {
25-
let mut listener = TcpListener::bind(&SocketAddr::from(([0, 0, 0, 0], 10007))).await?;
26-
listener
27-
.incoming()
28-
.for_each(|tcp_stream| {
29-
if let Ok(mut stream) = tcp_stream {
30-
tokio::spawn(async move {
31-
let (mut reader, mut writer) = stream.split();
32-
copy(&mut reader, &mut writer).await.unwrap();
33-
});
34-
}
35-
36-
future::ready(())
37-
})
38-
.await;
39-
Ok(())
24+
let listener = TcpListener::bind(&SocketAddr::from(([0, 0, 0, 0], 10007))).await?;
25+
loop {
26+
let (mut stream, _) = listener.accept().await?;
27+
tokio::spawn(async move {
28+
let (mut reader, mut writer) = stream.split();
29+
copy(&mut reader, &mut writer).await.unwrap();
30+
});
31+
}
4032
}
4133

4234
pub async fn reply_response<S: AsyncRead + AsyncWrite + Unpin>(mut socket: Socks5Stream<S>) -> Result<[u8; 5]> {

tests/long_username_password_auth.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ use tokio_socks::{
88

99
#[test]
1010
fn connect_long_username_password() -> Result<()> {
11-
let mut runtime = runtime().lock().unwrap();
11+
let runtime = runtime().lock().unwrap();
1212
let conn = runtime.block_on(Socks5Stream::connect_with_password(
1313
PROXY_ADDR, ECHO_SERVER_ADDR, "mylonglonglonglonglonglonglonglonglonglonglonglonglonglonglonglonglonglonglonglonglonglonglonglonglonglonglonglonglonglonglonglonglonglonglonglonglonglonglonglonglonglonglonglonglonglonglonglonglonglonglonglonglonglonglonglonglonglonglogin",
1414
"longlonglonglonglonglonglonglonglonglonglonglonglonglonglonglonglonglonglonglonglonglonglonglonglonglonglonglonglonglonglonglonglonglonglonglonglonglonglonglonglonglonglonglonglonglonglonglonglonglonglonglonglonglonglonglonglonglonglonglonglongpassword"))?;
@@ -18,7 +18,7 @@ fn connect_long_username_password() -> Result<()> {
1818
#[test]
1919
fn bind_long_username_password() -> Result<()> {
2020
let bind = {
21-
let mut runtime = runtime().lock().unwrap();
21+
let runtime = runtime().lock().unwrap();
2222
runtime.block_on(Socks5Listener::bind_with_password(
2323
PROXY_ADDR,
2424
ECHO_SERVER_ADDR,
@@ -31,7 +31,7 @@ fn bind_long_username_password() -> Result<()> {
3131

3232
#[test]
3333
fn connect_with_socket_long_username_password() -> Result<()> {
34-
let mut runtime = runtime().lock().unwrap();
34+
let runtime = runtime().lock().unwrap();
3535
let socket = runtime.block_on(connect_unix())?;
3636
let conn = runtime.block_on(Socks5Stream::connect_with_password_and_socket(
3737
socket, ECHO_SERVER_ADDR, "mylonglonglonglonglonglonglonglonglonglonglonglonglonglonglonglonglonglonglonglonglonglonglonglonglonglonglonglonglonglonglonglonglonglonglonglonglonglonglonglonglonglonglonglonglonglonglonglonglonglonglonglonglonglonglonglonglonglonglogin",
@@ -42,7 +42,7 @@ fn connect_with_socket_long_username_password() -> Result<()> {
4242
#[test]
4343
fn bind_with_socket_long_username_password() -> Result<()> {
4444
let bind = {
45-
let mut runtime = runtime().lock().unwrap();
45+
let runtime = runtime().lock().unwrap();
4646
let socket = runtime.block_on(connect_unix())?;
4747
runtime.block_on(Socks5Listener::bind_with_password_and_socket(
4848
socket,

tests/no_auth.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,23 +9,23 @@ use tokio_socks::{
99

1010
#[test]
1111
fn connect_no_auth() -> Result<()> {
12-
let mut runtime = runtime().lock().unwrap();
12+
let runtime = runtime().lock().unwrap();
1313
let conn = runtime.block_on(Socks5Stream::connect(PROXY_ADDR, ECHO_SERVER_ADDR))?;
1414
runtime.block_on(test_connect(conn))
1515
}
1616

1717
#[test]
1818
fn bind_no_auth() -> Result<()> {
1919
let bind = {
20-
let mut runtime = runtime().lock().unwrap();
20+
let runtime = runtime().lock().unwrap();
2121
runtime.block_on(Socks5Listener::bind(PROXY_ADDR, ECHO_SERVER_ADDR))
2222
}?;
2323
test_bind(bind)
2424
}
2525

2626
#[test]
2727
fn connect_with_socket_no_auth() -> Result<()> {
28-
let mut runtime = runtime().lock().unwrap();
28+
let runtime = runtime().lock().unwrap();
2929
let socket = runtime.block_on(connect_unix())?;
3030
let conn = runtime.block_on(Socks5Stream::connect_with_socket(socket, ECHO_SERVER_ADDR))?;
3131
runtime.block_on(test_connect(conn))
@@ -34,7 +34,7 @@ fn connect_with_socket_no_auth() -> Result<()> {
3434
#[test]
3535
fn bind_with_socket_no_auth() -> Result<()> {
3636
let bind = {
37-
let mut runtime = runtime().lock().unwrap();
37+
let runtime = runtime().lock().unwrap();
3838
let socket = runtime.block_on(connect_unix())?;
3939
runtime.block_on(Socks5Listener::bind_with_socket(socket, ECHO_SERVER_ADDR))
4040
}?;

tests/username_auth.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ use tokio_socks::{
88

99
#[test]
1010
fn connect_username_auth() -> Result<()> {
11-
let mut runtime = runtime().lock().unwrap();
11+
let runtime = runtime().lock().unwrap();
1212
let conn = runtime.block_on(Socks5Stream::connect_with_password(
1313
PROXY_ADDR,
1414
ECHO_SERVER_ADDR,
@@ -21,7 +21,7 @@ fn connect_username_auth() -> Result<()> {
2121
#[test]
2222
fn bind_username_auth() -> Result<()> {
2323
let bind = {
24-
let mut runtime = runtime().lock().unwrap();
24+
let runtime = runtime().lock().unwrap();
2525
runtime.block_on(Socks5Listener::bind_with_password(
2626
PROXY_ADDR,
2727
ECHO_SERVER_ADDR,
@@ -34,7 +34,7 @@ fn bind_username_auth() -> Result<()> {
3434

3535
#[test]
3636
fn connect_with_socket_username_auth() -> Result<()> {
37-
let mut runtime = runtime().lock().unwrap();
37+
let runtime = runtime().lock().unwrap();
3838
let socket = runtime.block_on(connect_unix())?;
3939
let conn = runtime.block_on(Socks5Stream::connect_with_password_and_socket(
4040
socket,
@@ -48,7 +48,7 @@ fn connect_with_socket_username_auth() -> Result<()> {
4848
#[test]
4949
fn bind_with_socket_username_auth() -> Result<()> {
5050
let bind = {
51-
let mut runtime = runtime().lock().unwrap();
51+
let runtime = runtime().lock().unwrap();
5252
let socket = runtime.block_on(connect_unix())?;
5353
runtime.block_on(Socks5Listener::bind_with_password_and_socket(
5454
socket,

0 commit comments

Comments
 (0)