44// https://www.apache.org/licenses/LICENSE-2.0>. This file may not be copied, modified, or distributed
55// except according to those terms.
66
7+ use crate :: utils:: { epoll_create1, epoll_ctl, epoll_wait, read, timerfd_create, timerfd_settime} ;
78use crate :: Result ;
89
910use std:: sync:: { mpsc:: Sender , Arc , Mutex } ;
@@ -57,8 +58,7 @@ impl Timer {
5758 let clockid: libc:: clockid_t = libc:: CLOCK_REALTIME ;
5859 let clock_flags: libc:: c_int = libc:: TFD_NONBLOCK ;
5960
60- // TODO: handler error (-1)
61- let tfd = unsafe { libc:: timerfd_create ( clockid, clock_flags) } ;
61+ let tfd = timerfd_create ( clockid, clock_flags) . unwrap ( ) ;
6262
6363 let now = std:: time:: SystemTime :: now ( )
6464 . duration_since ( std:: time:: UNIX_EPOCH ) ?
@@ -92,15 +92,13 @@ impl Timer {
9292
9393 let set_flags = libc:: TFD_TIMER_ABSTIME ;
9494
95- // TODO: handler error (-1)
96- let sfd = unsafe { libc:: timerfd_settime ( tfd, set_flags, & mut new_value, & mut old_value) } ;
95+ timerfd_settime ( tfd, set_flags, & mut new_value, & mut old_value) . unwrap ( ) ;
9796
9897 Ok ( tfd)
9998 }
10099
101100 fn create_epollfd ( timer_fd : libc:: c_int ) -> Result < libc:: c_int > {
102- // TODO: handler error (-1)
103- let epoll_fd = unsafe { libc:: epoll_create1 ( 0 ) } ;
101+ let epoll_fd = epoll_create1 ( 0 ) . unwrap ( ) ;
104102
105103 let mut event = libc:: epoll_event {
106104 events : libc:: EPOLLIN as u32 ,
@@ -109,22 +107,20 @@ impl Timer {
109107
110108 let epoll_flags = libc:: EPOLL_CTL_ADD ;
111109
112- // TODO: handler error (-1)
113- let ctl_fd = unsafe { libc:: epoll_ctl ( epoll_fd, epoll_flags, timer_fd, & mut event) } ;
110+ epoll_ctl ( epoll_fd, epoll_flags, timer_fd, & mut event) . unwrap ( ) ;
114111
115112 Ok ( epoll_fd)
116113 }
117114
118115 fn epoll_wait ( timer_fd : libc:: c_int , epoll_fd : libc:: c_int ) -> Result < ( ) > {
119116 let mut events = Vec :: with_capacity ( 1 ) ;
120117
121- // TODO: handler error ( -1)
122- let wait = unsafe { libc :: epoll_wait ( epoll_fd , events . as_mut_ptr ( ) , 1 , - 1 ) } ;
118+ epoll_wait ( epoll_fd , events . as_mut_ptr ( ) , 1 , -1 ) . unwrap ( ) ;
119+
123120 let mut buffer: u64 = 0 ;
124121 let bufptr: * mut _ = & mut buffer;
125122
126- // TODO: handler error (-1)
127- let read = unsafe { libc:: read ( timer_fd, bufptr as * mut libc:: c_void , 8 ) } ;
123+ read ( timer_fd, bufptr as * mut libc:: c_void , 8 ) . unwrap ( ) ;
128124
129125 Ok ( ( ) )
130126 }
0 commit comments