• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // Copyright (c) 2023 Huawei Device Co., Ltd.
2 // Licensed under the Apache License, Version 2.0 (the "License");
3 // you may not use this file except in compliance with the License.
4 // You may obtain a copy of the License at
5 //
6 //     http://www.apache.org/licenses/LICENSE-2.0
7 //
8 // Unless required by applicable law or agreed to in writing, software
9 // distributed under the License is distributed on an "AS IS" BASIS,
10 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11 // See the License for the specific language governing permissions and
12 // limitations under the License.
13 
14 use crate::{EventTrait, Token};
15 
16 /// A vector of events
17 pub type Events = Vec<Event>;
18 
19 /// An io event
20 pub type Event = libc::epoll_event;
21 
22 impl EventTrait for Event {
token(&self) -> Token23     fn token(&self) -> Token {
24         Token(self.u64 as usize)
25     }
26 
is_readable(&self) -> bool27     fn is_readable(&self) -> bool {
28         (self.events as libc::c_int & libc::EPOLLIN) != 0
29             || (self.events as libc::c_int & libc::EPOLLPRI) != 0
30     }
31 
is_writable(&self) -> bool32     fn is_writable(&self) -> bool {
33         (self.events as libc::c_int & libc::EPOLLOUT) != 0
34     }
35 
is_read_closed(&self) -> bool36     fn is_read_closed(&self) -> bool {
37         self.events as libc::c_int & libc::EPOLLHUP != 0
38             || (self.events as libc::c_int & libc::EPOLLIN != 0
39                 && self.events as libc::c_int & libc::EPOLLRDHUP != 0)
40     }
41 
is_write_closed(&self) -> bool42     fn is_write_closed(&self) -> bool {
43         self.events as libc::c_int & libc::EPOLLHUP != 0
44             || (self.events as libc::c_int & libc::EPOLLOUT != 0
45                 && self.events as libc::c_int & libc::EPOLLERR != 0)
46             || self.events as libc::c_int == libc::EPOLLERR
47     }
48 
is_error(&self) -> bool49     fn is_error(&self) -> bool {
50         (self.events as libc::c_int & libc::EPOLLERR) != 0
51     }
52 }
53