Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update the version and readme #76

Closed
wants to merge 5 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,5 @@
target/
**/*.rs.bk
Cargo.lock
.cargo/
wintun.dll
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "tun"
version = "0.6.1"
version = "0.6.2"
edition = "2021"

authors = ["meh. <[email protected]>"]
Expand Down
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ First, add the following to your `Cargo.toml`:

```toml
[dependencies]
tun = "0.6.1"
tun = "0.6.2"
```

Next, add this to your crate root:
Expand All @@ -21,7 +21,7 @@ If you want to use the TUN interface with mio/tokio, you need to enable the `asy

```toml
[dependencies]
tun = { version = "0.6.1", features = ["async"] }
tun = { version = "0.6.2", features = ["async"] }
```

Example
Expand Down
139 changes: 70 additions & 69 deletions src/async/win/device.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ use tokio::io::{AsyncRead, AsyncWrite, ReadBuf};
use tokio_util::codec::Framed;

use crate::device::Device as D;
use crate::platform::{Device, Queue};
use crate::platform::Device;
use crate::r#async::codec::*;

pub struct AsyncDevice {
Expand Down Expand Up @@ -56,10 +56,9 @@ impl AsyncRead for AsyncDevice {
cx: &mut Context<'_>,
buf: &mut ReadBuf<'_>,
) -> Poll<io::Result<()>> {
let rbuf = buf.initialize_unfilled();
match Pin::new(&mut self.inner).poll_read(cx, rbuf) {
Poll::Ready(Ok(n)) => {
buf.advance(n);
//let rbuf = buf.initialize_unfilled();
match Pin::new(&mut self.inner).poll_read(cx, buf) {
Poll::Ready(Ok(_)) => {
Poll::Ready(Ok(()))
}
Poll::Ready(Err(e)) => Poll::Ready(Err(e)),
Expand Down Expand Up @@ -92,67 +91,69 @@ impl AsyncWrite for AsyncDevice {
}
}

pub struct AsyncQueue {
inner: Queue,
}

impl AsyncQueue {
/// Create a new `AsyncQueue` wrapping around a `Queue`.
pub fn new(queue: Queue) -> io::Result<AsyncQueue> {
Ok(AsyncQueue { inner: queue })
}
/// Returns a shared reference to the underlying Queue object
pub fn get_ref(&self) -> &Queue {
&self.inner
}

/// Returns a mutable reference to the underlying Queue object
pub fn get_mut(&mut self) -> &mut Queue {
&mut self.inner
}

/// Consumes this AsyncQueue and return a Framed object (unified Stream and Sink interface)
pub fn into_framed(self) -> Framed<Self, TunPacketCodec> {
let codec = TunPacketCodec::new(false, 1512);
Framed::new(self, codec)
}
}

impl AsyncRead for AsyncQueue {
fn poll_read(
mut self: Pin<&mut Self>,
cx: &mut Context<'_>,
buf: &mut ReadBuf<'_>,
) -> Poll<io::Result<()>> {
let rbuf = buf.initialize_unfilled();
match Pin::new(&mut self.inner).poll_read(cx, rbuf) {
Poll::Ready(Ok(n)) => {
buf.advance(n);
Poll::Ready(Ok(()))
}
Poll::Ready(Err(e)) => Poll::Ready(Err(e)),
Poll::Pending => Poll::Pending,
}
}
}

impl AsyncWrite for AsyncQueue {
fn poll_write(
mut self: Pin<&mut Self>,
_cx: &mut Context<'_>,
buf: &[u8],
) -> Poll<Result<usize, Error>> {
match self.inner.write(buf) {
Ok(n) => Poll::Ready(Ok(n)),
Err(e) => Poll::Ready(Err(e)),
}
}

fn poll_flush(self: Pin<&mut Self>, _cx: &mut Context<'_>) -> Poll<Result<(), Error>> {
Poll::Ready(Ok(()))
}

fn poll_shutdown(self: Pin<&mut Self>, _cx: &mut Context<'_>) -> Poll<Result<(), Error>> {
Poll::Ready(Ok(()))
}
}
pub struct AsyncQueue;

// pub struct AsyncQueue {
// inner: Queue,
// }

// impl AsyncQueue {
// /// Create a new `AsyncQueue` wrapping around a `Queue`.
// pub fn new(queue: Queue) -> io::Result<AsyncQueue> {
// Ok(AsyncQueue { inner: queue })
// }
// /// Returns a shared reference to the underlying Queue object
// pub fn get_ref(&self) -> &Queue {
// &self.inner
// }

// /// Returns a mutable reference to the underlying Queue object
// pub fn get_mut(&mut self) -> &mut Queue {
// &mut self.inner
// }

// /// Consumes this AsyncQueue and return a Framed object (unified Stream and Sink interface)
// pub fn into_framed(self) -> Framed<Self, TunPacketCodec> {
// let codec = TunPacketCodec::new(false, 1512);
// Framed::new(self, codec)
// }
// }

// impl AsyncRead for AsyncQueue {
// fn poll_read(
// mut self: Pin<&mut Self>,
// cx: &mut Context<'_>,
// buf: &mut ReadBuf<'_>,
// ) -> Poll<io::Result<()>> {
// let rbuf = buf.initialize_unfilled();
// match Pin::new(&mut self.inner).poll_read(cx, rbuf) {
// Poll::Ready(Ok(n)) => {
// buf.advance(n);
// Poll::Ready(Ok(()))
// }
// Poll::Ready(Err(e)) => Poll::Ready(Err(e)),
// Poll::Pending => Poll::Pending,
// }
// }
// }

// impl AsyncWrite for AsyncQueue {
// fn poll_write(
// mut self: Pin<&mut Self>,
// _cx: &mut Context<'_>,
// buf: &[u8],
// ) -> Poll<Result<usize, Error>> {
// match self.inner.write(buf) {
// Ok(n) => Poll::Ready(Ok(n)),
// Err(e) => Poll::Ready(Err(e)),
// }
// }

// fn poll_flush(self: Pin<&mut Self>, _cx: &mut Context<'_>) -> Poll<Result<(), Error>> {
// Poll::Ready(Ok(()))
// }

// fn poll_shutdown(self: Pin<&mut Self>, _cx: &mut Context<'_>) -> Poll<Result<(), Error>> {
// Poll::Ready(Ok(()))
// }
// }
Loading
Loading