File tree Expand file tree Collapse file tree 2 files changed +15
-4
lines changed Expand file tree Collapse file tree 2 files changed +15
-4
lines changed Original file line number Diff line number Diff line change @@ -364,9 +364,21 @@ pub struct BreakLoop {
364364 handle : Weak < Handle > ,
365365}
366366
367+ unsafe impl Send for BreakLoop { }
368+ unsafe impl Sync for BreakLoop { }
369+
367370impl BreakLoop {
368371 /// Calls `pcap_breakloop` to make the blocking loop of a pcap capture return.
369372 /// The call is a no-op if the handle is invalid.
373+ ///
374+ /// # Safety
375+ ///
376+ /// Can be called from any thread, but **must not** be used inside a
377+ /// signal handler unless the owning `Capture` is guaranteed to still
378+ /// be alive.
379+ ///
380+ /// The signal handler should defer the execution of `BreakLoop::breakloop()`
381+ /// to a thread instead for safety.
370382 pub fn breakloop ( & self ) {
371383 if let Some ( handle) = self . handle . upgrade ( ) {
372384 unsafe { raw:: pcap_breakloop ( handle. as_ptr ( ) ) } ;
Original file line number Diff line number Diff line change @@ -105,18 +105,17 @@ impl Handle {
105105 }
106106}
107107
108+ // `PcapHandle` is safe to Send as it encapsulates the entire lifetime of `raw::pcap_t *`, but it is
109+ // not safe to Sync as libpcap does not promise thread-safe access to the same `raw::pcap_t *` from
110+ // multiple threads.
108111unsafe impl Send for Handle { }
109- unsafe impl Sync for Handle { }
110112
111113impl Drop for Handle {
112114 fn drop ( & mut self ) {
113115 unsafe { raw:: pcap_close ( self . handle . as_ptr ( ) ) }
114116 }
115117}
116118
117- // A Capture is safe to Send as it encapsulates the entire lifetime of `raw::pcap_t *`, but it is
118- // not safe to Sync as libpcap does not promise thread-safe access to the same `raw::pcap_t *` from
119- // multiple threads.
120119unsafe impl < T : State + ?Sized > Send for Capture < T > { }
121120
122121impl < T : State + ?Sized > From < NonNull < raw:: pcap_t > > for Capture < T > {
You can’t perform that action at this time.
0 commit comments