Skip to content

Commit fff3fc9

Browse files
committed
use a bounded channel for the packets stream
1 parent 3542e65 commit fff3fc9

2 files changed

Lines changed: 3 additions & 3 deletions

File tree

src/networking/parse_packets.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ pub fn parse_packets(
5252
// instant of the first parsed packet plus multiples of 1 second (only used in live captures)
5353
let mut first_packet_ticks = None;
5454

55-
let (pcap_tx, pcap_rx) = std::sync::mpsc::channel();
55+
let (pcap_tx, pcap_rx) = std::sync::mpsc::sync_channel(10_000);
5656
let _ = thread::Builder::new()
5757
.name("thread_packet_stream".to_string())
5858
.spawn(move || packet_stream(cap, &pcap_tx))
@@ -485,7 +485,7 @@ fn maybe_send_tick_run_offline(
485485

486486
fn packet_stream(
487487
mut cap: CaptureType,
488-
tx: &std::sync::mpsc::Sender<(Result<PacketOwned, pcap::Error>, Option<pcap::Stat>)>,
488+
tx: &std::sync::mpsc::SyncSender<(Result<PacketOwned, pcap::Error>, Option<pcap::Stat>)>,
489489
) {
490490
loop {
491491
let packet_res = cap.next_packet();

src/networking/types/capture_context.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,7 @@ impl CaptureType {
129129
let inactive = Capture::from_device(device.to_pcap_device())?;
130130
let cap = inactive
131131
.promisc(true)
132-
.buffer_size(2_000_000) // 2MB buffer
132+
.buffer_size(2_000_000) // 2MB buffer -> 10k packets of 200 bytes
133133
.snaplen(if pcap_out_path.is_some() {
134134
i32::from(u16::MAX)
135135
} else {

0 commit comments

Comments
 (0)