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

Add Send trait bound to create_reader so I can use this in async context #45

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
8 changes: 4 additions & 4 deletions src/capture.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,9 @@ pub trait Capture {
pub fn create_reader<'b, R>(
capacity: usize,
mut reader: R,
) -> Result<Box<dyn PcapReaderIterator + 'b>, PcapError<&'static [u8]>>
) -> Result<Box<dyn PcapReaderIterator + Send + 'b>, PcapError<&'static [u8]>>
where
R: Read + 'b,
R: Read + Send + 'b,
{
let mut buffer = Buffer::with_capacity(capacity);
let sz = reader.read(buffer.space()).or(Err(PcapError::ReadError))?;
Expand All @@ -46,11 +46,11 @@ where
// just check that first block is a valid one
if parse_sectionheaderblock(buffer.data()).is_ok() {
return PcapNGReader::from_buffer(buffer, reader)
.map(|r| Box::new(r) as Box<dyn PcapReaderIterator>);
.map(|r| Box::new(r) as Box<dyn PcapReaderIterator + Send>);
}
match parse_pcap_header(buffer.data()) {
Ok(_) => LegacyPcapReader::from_buffer(buffer, reader)
.map(|r| Box::new(r) as Box<dyn PcapReaderIterator>),
.map(|r| Box::new(r) as Box<dyn PcapReaderIterator + Send>),
Err(nom::Err::Incomplete(Needed::Size(n))) => Err(PcapError::Incomplete(n.into())),
Err(nom::Err::Incomplete(Needed::Unknown)) => Err(PcapError::Incomplete(0)),
_ => Err(PcapError::HeaderNotRecognized),
Expand Down