xref: /aosp_15_r20/external/crosvm/base/src/notifiers.rs (revision bb4ee6a4ae7042d18b07a98463b9c8b875e44b39)
1 // Copyright 2022 The ChromiumOS Authors
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4 
5 use crate::descriptor::AsRawDescriptor;
6 
7 pub trait ReadNotifier {
8     /// Gets a descriptor that can be used in EventContext to wait for events to be available (e.g.
9     /// to avoid receive_events blocking).
get_read_notifier(&self) -> &dyn AsRawDescriptor10     fn get_read_notifier(&self) -> &dyn AsRawDescriptor;
11 }
12 
13 impl ReadNotifier for std::fs::File {
get_read_notifier(&self) -> &dyn AsRawDescriptor14     fn get_read_notifier(&self) -> &dyn AsRawDescriptor {
15         self
16     }
17 }
18 
19 pub trait CloseNotifier {
20     /// Gets a descriptor that can be used in EventContext to wait for the closed event.
get_close_notifier(&self) -> &dyn AsRawDescriptor21     fn get_close_notifier(&self) -> &dyn AsRawDescriptor;
22 }
23