File tree Expand file tree Collapse file tree 2 files changed +16
-1
lines changed Expand file tree Collapse file tree 2 files changed +16
-1
lines changed Original file line number Diff line number Diff line change @@ -7,6 +7,7 @@ pub struct Config {
77 buffer_size : u32 ,
88 bpf : Option < String > ,
99 buffer_for : std:: time:: Duration ,
10+ blocking : bool ,
1011}
1112
1213impl Config {
@@ -55,19 +56,30 @@ impl Config {
5556 self
5657 }
5758
59+ pub fn blocking ( & self ) -> bool {
60+ self . blocking
61+ }
62+
63+ pub fn with_blocking ( & mut self , blocking : bool ) -> & mut Self {
64+ self . blocking = blocking;
65+ self
66+ }
67+
5868 pub fn new (
5969 max_packets_read : usize ,
6070 snaplen : u32 ,
6171 buffer_size : u32 ,
6272 bpf : Option < String > ,
6373 buffer_for : std:: time:: Duration ,
74+ blocking : bool ,
6475 ) -> Config {
6576 Config {
6677 max_packets_read,
6778 snaplen,
6879 buffer_size,
6980 bpf,
7081 buffer_for,
82+ blocking,
7183 }
7284 }
7385}
@@ -80,6 +92,7 @@ impl Default for Config {
8092 buffer_size : 16777216 ,
8193 bpf : None ,
8294 buffer_for : std:: time:: Duration :: from_millis ( 100 ) ,
95+ blocking : false ,
8396 }
8497 }
8598}
Original file line number Diff line number Diff line change @@ -33,7 +33,9 @@ impl PacketStream {
3333 . set_promiscuous ( ) ?
3434 . set_buffer_size ( config. buffer_size ( ) ) ?
3535 . activate ( ) ?;
36- h. set_non_block ( ) ?;
36+ if !config. blocking ( ) {
37+ h. set_non_block ( ) ?;
38+ }
3739
3840 if let Some ( bpf) = config. bpf ( ) {
3941 let bpf = handle. compile_bpf ( bpf) ?;
You can’t perform that action at this time.
0 commit comments