-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Dima Dorezyuk
committed
Dec 6, 2023
1 parent
d9b47b1
commit 4ff2f19
Showing
6 changed files
with
93 additions
and
5 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,6 @@ | ||
pub mod constants; | ||
pub mod feig; | ||
pub mod logging; | ||
pub mod packets; | ||
pub mod sequences; | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
use log::debug; | ||
use pin_project::pin_project; | ||
use std::pin::Pin; | ||
use std::task::Poll; | ||
use tokio::io::{AsyncRead, AsyncWrite}; | ||
|
||
/// Wrapper around an io interface which will log on successful read and write. | ||
/// | ||
/// The logging happens every time the async methods return [Poll::Ready], | ||
/// assuming the runtime will not poll them after this point. | ||
#[pin_project] | ||
pub struct LoggingSource<Source> { | ||
#[pin] | ||
pub source: Source, | ||
} | ||
|
||
impl<Source> AsyncRead for LoggingSource<Source> | ||
where | ||
Source: AsyncRead + Send, | ||
{ | ||
fn poll_read( | ||
self: Pin<&mut Self>, | ||
cx: &mut std::task::Context<'_>, | ||
buf: &mut tokio::io::ReadBuf<'_>, | ||
) -> std::task::Poll<std::io::Result<()>> { | ||
let res = self.project().source.poll_read(cx, buf); | ||
if let Poll::Ready(_) = res { | ||
debug!("Read the bytes {:?}", buf) | ||
} | ||
|
||
res | ||
} | ||
} | ||
|
||
impl<Source> AsyncWrite for LoggingSource<Source> | ||
where | ||
Source: AsyncWrite, | ||
{ | ||
fn poll_write( | ||
self: Pin<&mut Self>, | ||
cx: &mut std::task::Context<'_>, | ||
buf: &[u8], | ||
) -> std::task::Poll<std::prelude::v1::Result<usize, std::io::Error>> { | ||
let res = self.project().source.poll_write(cx, buf); | ||
if let Poll::Ready(_) = res { | ||
debug!("Write the bytes {:?}", buf); | ||
} | ||
|
||
res | ||
} | ||
|
||
fn poll_flush( | ||
self: Pin<&mut Self>, | ||
cx: &mut std::task::Context<'_>, | ||
) -> std::task::Poll<std::prelude::v1::Result<(), std::io::Error>> { | ||
// No logging here. | ||
self.project().source.poll_flush(cx) | ||
} | ||
|
||
fn poll_shutdown( | ||
self: Pin<&mut Self>, | ||
cx: &mut std::task::Context<'_>, | ||
) -> std::task::Poll<std::prelude::v1::Result<(), std::io::Error>> { | ||
// No logging here. | ||
self.project().source.poll_shutdown(cx) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters