@@ -5,20 +5,24 @@ use std::convert::TryInto;
5
5
use std:: mem:: MaybeUninit ;
6
6
7
7
fn main ( ) {
8
+ test_epoll_socketpair ( ) ;
9
+ test_epoll_socketpair_both_sides ( ) ;
10
+ test_socketpair_read ( ) ;
11
+ test_epoll_eventfd ( ) ;
12
+
8
13
test_event_overwrite ( ) ;
9
14
test_not_fully_closed_fd ( ) ;
10
15
test_closed_fd ( ) ;
11
- test_epoll_socketpair_special_case ( ) ;
12
16
test_two_epoll_instance ( ) ;
13
17
test_epoll_ctl_mod ( ) ;
14
- test_epoll_socketpair ( ) ;
15
- test_epoll_eventfd ( ) ;
16
18
test_epoll_ctl_del ( ) ;
17
19
test_pointer ( ) ;
18
20
test_two_same_fd_in_same_epoll_instance ( ) ;
19
- test_socketpair_read ( ) ;
20
21
}
21
22
23
+ // Using `as` cast since `EPOLLET` wraps around
24
+ const EPOLL_IN_OUT_ET : u32 = ( libc:: EPOLLIN | libc:: EPOLLOUT | libc:: EPOLLET ) as _ ;
25
+
22
26
#[ track_caller]
23
27
fn check_epoll_wait < const N : usize > (
24
28
epfd : i32 ,
@@ -58,21 +62,17 @@ fn test_epoll_socketpair() {
58
62
59
63
// Create a socketpair instance.
60
64
let mut fds = [ -1 , -1 ] ;
61
- let mut res =
62
- unsafe { libc:: socketpair ( libc:: AF_UNIX , libc:: SOCK_STREAM , 0 , fds. as_mut_ptr ( ) ) } ;
65
+ let res = unsafe { libc:: socketpair ( libc:: AF_UNIX , libc:: SOCK_STREAM , 0 , fds. as_mut_ptr ( ) ) } ;
63
66
assert_eq ! ( res, 0 ) ;
64
67
65
68
// Write to fd[0]
66
69
let data = "abcde" . as_bytes ( ) . as_ptr ( ) ;
67
- res = unsafe { libc:: write ( fds[ 0 ] , data as * const libc:: c_void , 5 ) . try_into ( ) . unwrap ( ) } ;
70
+ let res = unsafe { libc:: write ( fds[ 0 ] , data as * const libc:: c_void , 5 ) } ;
68
71
assert_eq ! ( res, 5 ) ;
69
72
70
- // Register fd[1] with EPOLLIN|EPOLLOUT|EPOLLET
71
- // EPOLLET is negative number for i32 so casting is needed to do proper bitwise OR for u32.
72
- let epollet = libc:: EPOLLET as u32 ;
73
- let flags = u32:: try_from ( libc:: EPOLLIN | libc:: EPOLLOUT | libc:: EPOLLRDHUP ) . unwrap ( ) | epollet;
73
+ // Register fd[1] with EPOLLIN|EPOLLOUT|EPOLLET|EPOLLRDHUP
74
74
let mut ev = libc:: epoll_event {
75
- events : u32 :: try_from ( flags ) . unwrap ( ) ,
75
+ events : ( libc :: EPOLLIN | libc :: EPOLLOUT | libc :: EPOLLET | libc :: EPOLLRDHUP ) as _ ,
76
76
u64 : u64:: try_from ( fds[ 1 ] ) . unwrap ( ) ,
77
77
} ;
78
78
let res = unsafe { libc:: epoll_ctl ( epfd, libc:: EPOLL_CTL_ADD , fds[ 1 ] , & mut ev) } ;
@@ -100,23 +100,17 @@ fn test_epoll_ctl_mod() {
100
100
101
101
// Create a socketpair instance.
102
102
let mut fds = [ -1 , -1 ] ;
103
- let mut res =
104
- unsafe { libc:: socketpair ( libc:: AF_UNIX , libc:: SOCK_STREAM , 0 , fds. as_mut_ptr ( ) ) } ;
103
+ let res = unsafe { libc:: socketpair ( libc:: AF_UNIX , libc:: SOCK_STREAM , 0 , fds. as_mut_ptr ( ) ) } ;
105
104
assert_eq ! ( res, 0 ) ;
106
105
107
106
// Write to fd[0].
108
107
let data = "abcde" . as_bytes ( ) . as_ptr ( ) ;
109
- res = unsafe { libc:: write ( fds[ 0 ] , data as * const libc:: c_void , 5 ) . try_into ( ) . unwrap ( ) } ;
108
+ let res = unsafe { libc:: write ( fds[ 0 ] , data as * const libc:: c_void , 5 ) } ;
110
109
assert_eq ! ( res, 5 ) ;
111
110
112
111
// Register fd[1] with EPOLLIN|EPOLLOUT|EPOLLET.
113
- // EPOLLET is negative number for i32 so casting is needed to do proper bitwise OR for u32.
114
- let epollet = libc:: EPOLLET as u32 ;
115
- let mut flags = u32:: try_from ( libc:: EPOLLIN | libc:: EPOLLOUT ) . unwrap ( ) | epollet;
116
- let mut ev = libc:: epoll_event {
117
- events : u32:: try_from ( flags) . unwrap ( ) ,
118
- u64 : u64:: try_from ( fds[ 1 ] ) . unwrap ( ) ,
119
- } ;
112
+ // (Not using checked cast as EPOLLET wraps around.)
113
+ let mut ev = libc:: epoll_event { events : EPOLL_IN_OUT_ET , u64 : u64:: try_from ( fds[ 1 ] ) . unwrap ( ) } ;
120
114
let res = unsafe { libc:: epoll_ctl ( epfd, libc:: EPOLL_CTL_ADD , fds[ 1 ] , & mut ev) } ;
121
115
assert_ne ! ( res, -1 ) ;
122
116
@@ -126,9 +120,8 @@ fn test_epoll_ctl_mod() {
126
120
assert ! ( check_epoll_wait:: <8 >( epfd, vec![ ( expected_event, expected_value) ] ) ) ;
127
121
128
122
// Test EPOLLRDHUP.
129
- flags |= u32:: try_from ( libc:: EPOLLRDHUP ) . unwrap ( ) ;
130
123
let mut ev = libc:: epoll_event {
131
- events : u32 :: try_from ( flags ) . unwrap ( ) ,
124
+ events : ( libc :: EPOLLIN | libc :: EPOLLOUT | libc :: EPOLLET | libc :: EPOLLRDHUP ) as _ ,
132
125
u64 : u64:: try_from ( fds[ 1 ] ) . unwrap ( ) ,
133
126
} ;
134
127
let res = unsafe { libc:: epoll_ctl ( epfd, libc:: EPOLL_CTL_MOD , fds[ 1 ] , & mut ev) } ;
@@ -151,23 +144,16 @@ fn test_epoll_ctl_del() {
151
144
152
145
// Create a socketpair instance.
153
146
let mut fds = [ -1 , -1 ] ;
154
- let mut res =
155
- unsafe { libc:: socketpair ( libc:: AF_UNIX , libc:: SOCK_STREAM , 0 , fds. as_mut_ptr ( ) ) } ;
147
+ let res = unsafe { libc:: socketpair ( libc:: AF_UNIX , libc:: SOCK_STREAM , 0 , fds. as_mut_ptr ( ) ) } ;
156
148
assert_eq ! ( res, 0 ) ;
157
149
158
150
// Write to fd[0]
159
151
let data = "abcde" . as_bytes ( ) . as_ptr ( ) ;
160
- res = unsafe { libc:: write ( fds[ 0 ] , data as * const libc:: c_void , 5 ) . try_into ( ) . unwrap ( ) } ;
152
+ let res = unsafe { libc:: write ( fds[ 0 ] , data as * const libc:: c_void , 5 ) } ;
161
153
assert_eq ! ( res, 5 ) ;
162
154
163
155
// Register fd[1] with EPOLLIN|EPOLLOUT|EPOLLET
164
- // EPOLLET is negative number for i32 so casting is needed to do proper bitwise OR for u32.
165
- let epollet = libc:: EPOLLET as u32 ;
166
- let flags = u32:: try_from ( libc:: EPOLLIN | libc:: EPOLLOUT ) . unwrap ( ) | epollet;
167
- let mut ev = libc:: epoll_event {
168
- events : u32:: try_from ( flags) . unwrap ( ) ,
169
- u64 : u64:: try_from ( fds[ 1 ] ) . unwrap ( ) ,
170
- } ;
156
+ let mut ev = libc:: epoll_event { events : EPOLL_IN_OUT_ET , u64 : u64:: try_from ( fds[ 1 ] ) . unwrap ( ) } ;
171
157
let res = unsafe { libc:: epoll_ctl ( epfd, libc:: EPOLL_CTL_ADD , fds[ 1 ] , & mut ev) } ;
172
158
assert_ne ! ( res, -1 ) ;
173
159
@@ -185,22 +171,16 @@ fn test_two_epoll_instance() {
185
171
186
172
// Create a socketpair instance.
187
173
let mut fds = [ -1 , -1 ] ;
188
- let mut res =
189
- unsafe { libc:: socketpair ( libc:: AF_UNIX , libc:: SOCK_STREAM , 0 , fds. as_mut_ptr ( ) ) } ;
174
+ let res = unsafe { libc:: socketpair ( libc:: AF_UNIX , libc:: SOCK_STREAM , 0 , fds. as_mut_ptr ( ) ) } ;
190
175
assert_eq ! ( res, 0 ) ;
191
176
192
177
// Write to the socketpair.
193
178
let data = "abcde" . as_bytes ( ) . as_ptr ( ) ;
194
- res = unsafe { libc:: write ( fds[ 0 ] , data as * const libc:: c_void , 5 ) . try_into ( ) . unwrap ( ) } ;
179
+ let res = unsafe { libc:: write ( fds[ 0 ] , data as * const libc:: c_void , 5 ) } ;
195
180
assert_eq ! ( res, 5 ) ;
196
181
197
182
// Register one side of the socketpair with EPOLLIN | EPOLLOUT | EPOLLET.
198
- let epollet = libc:: EPOLLET as u32 ;
199
- let flags = u32:: try_from ( libc:: EPOLLIN | libc:: EPOLLOUT ) . unwrap ( ) | epollet;
200
- let mut ev = libc:: epoll_event {
201
- events : u32:: try_from ( flags) . unwrap ( ) ,
202
- u64 : u64:: try_from ( fds[ 1 ] ) . unwrap ( ) ,
203
- } ;
183
+ let mut ev = libc:: epoll_event { events : EPOLL_IN_OUT_ET , u64 : u64:: try_from ( fds[ 1 ] ) . unwrap ( ) } ;
204
184
let res = unsafe { libc:: epoll_ctl ( epfd1, libc:: EPOLL_CTL_ADD , fds[ 1 ] , & mut ev) } ;
205
185
assert_ne ! ( res, -1 ) ;
206
186
let res = unsafe { libc:: epoll_ctl ( epfd2, libc:: EPOLL_CTL_ADD , fds[ 1 ] , & mut ev) } ;
@@ -230,17 +210,15 @@ fn test_two_same_fd_in_same_epoll_instance() {
230
210
assert_ne ! ( newfd, -1 ) ;
231
211
232
212
// Register both fd to the same epoll instance.
233
- let epollet = libc:: EPOLLET as u32 ;
234
- let flags = u32:: try_from ( libc:: EPOLLIN | libc:: EPOLLOUT ) . unwrap ( ) | epollet;
235
- let mut ev = libc:: epoll_event { events : u32:: try_from ( flags) . unwrap ( ) , u64 : 5 as u64 } ;
236
- let mut res = unsafe { libc:: epoll_ctl ( epfd, libc:: EPOLL_CTL_ADD , fds[ 1 ] , & mut ev) } ;
213
+ let mut ev = libc:: epoll_event { events : EPOLL_IN_OUT_ET , u64 : 5 as u64 } ;
214
+ let res = unsafe { libc:: epoll_ctl ( epfd, libc:: EPOLL_CTL_ADD , fds[ 1 ] , & mut ev) } ;
237
215
assert_ne ! ( res, -1 ) ;
238
- res = unsafe { libc:: epoll_ctl ( epfd, libc:: EPOLL_CTL_ADD , newfd, & mut ev) } ;
216
+ let res = unsafe { libc:: epoll_ctl ( epfd, libc:: EPOLL_CTL_ADD , newfd, & mut ev) } ;
239
217
assert_ne ! ( res, -1 ) ;
240
218
241
219
// Write to the socketpair.
242
220
let data = "abcde" . as_bytes ( ) . as_ptr ( ) ;
243
- res = unsafe { libc:: write ( fds[ 0 ] , data as * const libc:: c_void , 5 ) . try_into ( ) . unwrap ( ) } ;
221
+ let res = unsafe { libc:: write ( fds[ 0 ] , data as * const libc:: c_void , 5 ) } ;
244
222
assert_eq ! ( res, 5 ) ;
245
223
246
224
//Two notification should be received.
@@ -259,23 +237,15 @@ fn test_epoll_eventfd() {
259
237
260
238
// Write to the eventfd instance.
261
239
let sized_8_data: [ u8 ; 8 ] = 1_u64 . to_ne_bytes ( ) ;
262
- let res: i32 = unsafe {
263
- libc:: write ( fd, sized_8_data. as_ptr ( ) as * const libc:: c_void , 8 ) . try_into ( ) . unwrap ( )
264
- } ;
240
+ let res = unsafe { libc:: write ( fd, sized_8_data. as_ptr ( ) as * const libc:: c_void , 8 ) } ;
265
241
assert_eq ! ( res, 8 ) ;
266
242
267
243
// Create an epoll instance.
268
244
let epfd = unsafe { libc:: epoll_create1 ( 0 ) } ;
269
245
assert_ne ! ( epfd, -1 ) ;
270
246
271
247
// Register eventfd with EPOLLIN | EPOLLOUT | EPOLLET
272
- // EPOLLET is negative number for i32 so casting is needed to do proper bitwise OR for u32.
273
- let epollet = libc:: EPOLLET as u32 ;
274
- let flags = u32:: try_from ( libc:: EPOLLIN | libc:: EPOLLOUT ) . unwrap ( ) | epollet;
275
- let mut ev = libc:: epoll_event {
276
- events : u32:: try_from ( flags) . unwrap ( ) ,
277
- u64 : u64:: try_from ( fd) . unwrap ( ) ,
278
- } ;
248
+ let mut ev = libc:: epoll_event { events : EPOLL_IN_OUT_ET , u64 : u64:: try_from ( fd) . unwrap ( ) } ;
279
249
let res = unsafe { libc:: epoll_ctl ( epfd, libc:: EPOLL_CTL_ADD , fd, & mut ev) } ;
280
250
assert_ne ! ( res, -1 ) ;
281
251
@@ -296,20 +266,15 @@ fn test_pointer() {
296
266
assert_eq ! ( res, 0 ) ;
297
267
298
268
// Register fd[1] with EPOLLIN|EPOLLOUT|EPOLLET
299
- // EPOLLET is negative number for i32 so casting is needed to do proper bitwise OR for u32.
300
- let epollet = libc:: EPOLLET as u32 ;
301
- let flags = u32:: try_from ( libc:: EPOLLIN | libc:: EPOLLOUT | libc:: EPOLLRDHUP ) . unwrap ( ) | epollet;
302
269
let data = MaybeUninit :: < u64 > :: uninit ( ) . as_ptr ( ) ;
303
- let mut ev = libc:: epoll_event {
304
- events : u32:: try_from ( flags) . unwrap ( ) ,
305
- u64 : data. expose_provenance ( ) as u64 ,
306
- } ;
270
+ let mut ev =
271
+ libc:: epoll_event { events : EPOLL_IN_OUT_ET , u64 : data. expose_provenance ( ) as u64 } ;
307
272
let res = unsafe { libc:: epoll_ctl ( epfd, libc:: EPOLL_CTL_ADD , fds[ 1 ] , & mut ev) } ;
308
273
assert_ne ! ( res, -1 ) ;
309
274
}
310
275
311
276
// When read/write happened on one side of the socketpair, only the other side will be notified.
312
- fn test_epoll_socketpair_special_case ( ) {
277
+ fn test_epoll_socketpair_both_sides ( ) {
313
278
// Create an epoll instance.
314
279
let epfd = unsafe { libc:: epoll_create1 ( 0 ) } ;
315
280
assert_ne ! ( epfd, -1 ) ;
@@ -320,18 +285,16 @@ fn test_epoll_socketpair_special_case() {
320
285
assert_eq ! ( res, 0 ) ;
321
286
322
287
// Register both fd to the same epoll instance.
323
- let epollet = libc:: EPOLLET as u32 ;
324
- let flags = u32:: try_from ( libc:: EPOLLIN | libc:: EPOLLOUT ) . unwrap ( ) | epollet;
325
- let mut ev = libc:: epoll_event { events : u32:: try_from ( flags) . unwrap ( ) , u64 : fds[ 0 ] as u64 } ;
326
- let mut res = unsafe { libc:: epoll_ctl ( epfd, libc:: EPOLL_CTL_ADD , fds[ 0 ] , & mut ev) } ;
288
+ let mut ev = libc:: epoll_event { events : EPOLL_IN_OUT_ET , u64 : fds[ 0 ] as u64 } ;
289
+ let res = unsafe { libc:: epoll_ctl ( epfd, libc:: EPOLL_CTL_ADD , fds[ 0 ] , & mut ev) } ;
327
290
assert_ne ! ( res, -1 ) ;
328
- let mut ev = libc:: epoll_event { events : u32 :: try_from ( flags ) . unwrap ( ) , u64 : fds[ 1 ] as u64 } ;
329
- res = unsafe { libc:: epoll_ctl ( epfd, libc:: EPOLL_CTL_ADD , fds[ 1 ] , & mut ev) } ;
291
+ let mut ev = libc:: epoll_event { events : EPOLL_IN_OUT_ET , u64 : fds[ 1 ] as u64 } ;
292
+ let res = unsafe { libc:: epoll_ctl ( epfd, libc:: EPOLL_CTL_ADD , fds[ 1 ] , & mut ev) } ;
330
293
assert_ne ! ( res, -1 ) ;
331
294
332
295
// Write to fds[1].
333
296
let data = "abcde" . as_bytes ( ) . as_ptr ( ) ;
334
- res = unsafe { libc:: write ( fds[ 1 ] , data as * const libc:: c_void , 5 ) . try_into ( ) . unwrap ( ) } ;
297
+ let res = unsafe { libc:: write ( fds[ 1 ] , data as * const libc:: c_void , 5 ) } ;
335
298
assert_eq ! ( res, 5 ) ;
336
299
337
300
//Two notification should be received.
@@ -346,9 +309,7 @@ fn test_epoll_socketpair_special_case() {
346
309
347
310
// Read from fds[0].
348
311
let mut buf: [ u8 ; 5 ] = [ 0 ; 5 ] ;
349
- res = unsafe {
350
- libc:: read ( fds[ 0 ] , buf. as_mut_ptr ( ) . cast ( ) , buf. len ( ) as libc:: size_t ) . try_into ( ) . unwrap ( )
351
- } ;
312
+ let res = unsafe { libc:: read ( fds[ 0 ] , buf. as_mut_ptr ( ) . cast ( ) , buf. len ( ) as libc:: size_t ) } ;
352
313
assert_eq ! ( res, 5 ) ;
353
314
assert_eq ! ( buf, "abcde" . as_bytes( ) ) ;
354
315
@@ -370,21 +331,13 @@ fn test_closed_fd() {
370
331
let fd = unsafe { libc:: eventfd ( 0 , flags) } ;
371
332
372
333
// Register eventfd with EPOLLIN | EPOLLOUT | EPOLLET
373
- // EPOLLET is negative number for i32 so casting is needed to do proper bitwise OR for u32.
374
- let epollet = libc:: EPOLLET as u32 ;
375
- let flags = u32:: try_from ( libc:: EPOLLIN | libc:: EPOLLOUT ) . unwrap ( ) | epollet;
376
- let mut ev = libc:: epoll_event {
377
- events : u32:: try_from ( flags) . unwrap ( ) ,
378
- u64 : u64:: try_from ( fd) . unwrap ( ) ,
379
- } ;
334
+ let mut ev = libc:: epoll_event { events : EPOLL_IN_OUT_ET , u64 : u64:: try_from ( fd) . unwrap ( ) } ;
380
335
let res = unsafe { libc:: epoll_ctl ( epfd, libc:: EPOLL_CTL_ADD , fd, & mut ev) } ;
381
336
assert_ne ! ( res, -1 ) ;
382
337
383
338
// Write to the eventfd instance.
384
339
let sized_8_data: [ u8 ; 8 ] = 1_u64 . to_ne_bytes ( ) ;
385
- let res: i32 = unsafe {
386
- libc:: write ( fd, sized_8_data. as_ptr ( ) as * const libc:: c_void , 8 ) . try_into ( ) . unwrap ( )
387
- } ;
340
+ let res = unsafe { libc:: write ( fd, sized_8_data. as_ptr ( ) as * const libc:: c_void , 8 ) } ;
388
341
assert_eq ! ( res, 8 ) ;
389
342
390
343
// Close the eventfd.
@@ -415,13 +368,7 @@ fn test_not_fully_closed_fd() {
415
368
assert_ne ! ( newfd, -1 ) ;
416
369
417
370
// Register eventfd with EPOLLIN | EPOLLOUT | EPOLLET
418
- // EPOLLET is negative number for i32 so casting is needed to do proper bitwise OR for u32.
419
- let epollet = libc:: EPOLLET as u32 ;
420
- let flags = u32:: try_from ( libc:: EPOLLIN | libc:: EPOLLOUT ) . unwrap ( ) | epollet;
421
- let mut ev = libc:: epoll_event {
422
- events : u32:: try_from ( flags) . unwrap ( ) ,
423
- u64 : u64:: try_from ( fd) . unwrap ( ) ,
424
- } ;
371
+ let mut ev = libc:: epoll_event { events : EPOLL_IN_OUT_ET , u64 : u64:: try_from ( fd) . unwrap ( ) } ;
425
372
let res = unsafe { libc:: epoll_ctl ( epfd, libc:: EPOLL_CTL_ADD , fd, & mut ev) } ;
426
373
assert_ne ! ( res, -1 ) ;
427
374
@@ -436,9 +383,7 @@ fn test_not_fully_closed_fd() {
436
383
437
384
// Write to the eventfd instance to produce notification.
438
385
let sized_8_data: [ u8 ; 8 ] = 1_u64 . to_ne_bytes ( ) ;
439
- let res: i32 = unsafe {
440
- libc:: write ( newfd, sized_8_data. as_ptr ( ) as * const libc:: c_void , 8 ) . try_into ( ) . unwrap ( )
441
- } ;
386
+ let res = unsafe { libc:: write ( newfd, sized_8_data. as_ptr ( ) as * const libc:: c_void , 8 ) } ;
442
387
assert_eq ! ( res, 8 ) ;
443
388
444
389
// Close the dupped fd.
@@ -458,29 +403,24 @@ fn test_event_overwrite() {
458
403
459
404
// Write to the eventfd instance.
460
405
let sized_8_data: [ u8 ; 8 ] = 1_u64 . to_ne_bytes ( ) ;
461
- let res: i32 = unsafe {
462
- libc:: write ( fd, sized_8_data. as_ptr ( ) as * const libc:: c_void , 8 ) . try_into ( ) . unwrap ( )
463
- } ;
406
+ let res = unsafe { libc:: write ( fd, sized_8_data. as_ptr ( ) as * const libc:: c_void , 8 ) } ;
464
407
assert_eq ! ( res, 8 ) ;
465
408
466
409
// Create an epoll instance.
467
410
let epfd = unsafe { libc:: epoll_create1 ( 0 ) } ;
468
411
assert_ne ! ( epfd, -1 ) ;
469
412
470
413
// Register eventfd with EPOLLIN | EPOLLOUT | EPOLLET
471
- // EPOLLET is negative number for i32 so casting is needed to do proper bitwise OR for u32.
472
- let epollet = libc:: EPOLLET as u32 ;
473
- let flags = u32:: try_from ( libc:: EPOLLIN | libc:: EPOLLOUT ) . unwrap ( ) | epollet;
474
414
let mut ev = libc:: epoll_event {
475
- events : u32 :: try_from ( flags ) . unwrap ( ) ,
415
+ events : ( libc :: EPOLLIN | libc :: EPOLLOUT | libc :: EPOLLET ) as _ ,
476
416
u64 : u64:: try_from ( fd) . unwrap ( ) ,
477
417
} ;
478
418
let res = unsafe { libc:: epoll_ctl ( epfd, libc:: EPOLL_CTL_ADD , fd, & mut ev) } ;
479
419
assert_ne ! ( res, -1 ) ;
480
420
481
421
// Read from the eventfd instance.
482
422
let mut buf: [ u8 ; 8 ] = [ 0 ; 8 ] ;
483
- let res: i32 = unsafe { libc:: read ( fd, buf. as_mut_ptr ( ) . cast ( ) , 8 ) . try_into ( ) . unwrap ( ) } ;
423
+ let res = unsafe { libc:: read ( fd, buf. as_mut_ptr ( ) . cast ( ) , 8 ) } ;
484
424
assert_eq ! ( res, 8 ) ;
485
425
486
426
// Check result from epoll_wait.
@@ -502,18 +442,22 @@ fn test_socketpair_read() {
502
442
assert_eq ! ( res, 0 ) ;
503
443
504
444
// Register both fd to the same epoll instance.
505
- let epollet = libc:: EPOLLET as u32 ;
506
- let flags = u32:: try_from ( libc:: EPOLLIN | libc:: EPOLLOUT ) . unwrap ( ) | epollet;
507
- let mut ev = libc:: epoll_event { events : u32:: try_from ( flags) . unwrap ( ) , u64 : fds[ 0 ] as u64 } ;
508
- let mut res = unsafe { libc:: epoll_ctl ( epfd, libc:: EPOLL_CTL_ADD , fds[ 0 ] , & mut ev) } ;
445
+ let mut ev = libc:: epoll_event {
446
+ events : ( libc:: EPOLLIN | libc:: EPOLLOUT | libc:: EPOLLET ) as _ ,
447
+ u64 : fds[ 0 ] as u64 ,
448
+ } ;
449
+ let res = unsafe { libc:: epoll_ctl ( epfd, libc:: EPOLL_CTL_ADD , fds[ 0 ] , & mut ev) } ;
509
450
assert_ne ! ( res, -1 ) ;
510
- let mut ev = libc:: epoll_event { events : u32:: try_from ( flags) . unwrap ( ) , u64 : fds[ 1 ] as u64 } ;
511
- res = unsafe { libc:: epoll_ctl ( epfd, libc:: EPOLL_CTL_ADD , fds[ 1 ] , & mut ev) } ;
451
+ let mut ev = libc:: epoll_event {
452
+ events : ( libc:: EPOLLIN | libc:: EPOLLOUT | libc:: EPOLLET ) as _ ,
453
+ u64 : fds[ 1 ] as u64 ,
454
+ } ;
455
+ let res = unsafe { libc:: epoll_ctl ( epfd, libc:: EPOLL_CTL_ADD , fds[ 1 ] , & mut ev) } ;
512
456
assert_ne ! ( res, -1 ) ;
513
457
514
458
// Write 5 bytes to fds[1].
515
459
let data = "abcde" . as_bytes ( ) . as_ptr ( ) ;
516
- res = unsafe { libc:: write ( fds[ 1 ] , data as * const libc:: c_void , 5 ) . try_into ( ) . unwrap ( ) } ;
460
+ let res = unsafe { libc:: write ( fds[ 1 ] , data as * const libc:: c_void , 5 ) } ;
517
461
assert_eq ! ( res, 5 ) ;
518
462
519
463
//Two notification should be received.
@@ -528,9 +472,7 @@ fn test_socketpair_read() {
528
472
529
473
// Read 3 bytes from fds[0].
530
474
let mut buf: [ u8 ; 3 ] = [ 0 ; 3 ] ;
531
- res = unsafe {
532
- libc:: read ( fds[ 0 ] , buf. as_mut_ptr ( ) . cast ( ) , buf. len ( ) as libc:: size_t ) . try_into ( ) . unwrap ( )
533
- } ;
475
+ let res = unsafe { libc:: read ( fds[ 0 ] , buf. as_mut_ptr ( ) . cast ( ) , buf. len ( ) as libc:: size_t ) } ;
534
476
assert_eq ! ( res, 3 ) ;
535
477
assert_eq ! ( buf, "abc" . as_bytes( ) ) ;
536
478
@@ -542,9 +484,7 @@ fn test_socketpair_read() {
542
484
543
485
// Read until the buffer is empty.
544
486
let mut buf: [ u8 ; 2 ] = [ 0 ; 2 ] ;
545
- res = unsafe {
546
- libc:: read ( fds[ 0 ] , buf. as_mut_ptr ( ) . cast ( ) , buf. len ( ) as libc:: size_t ) . try_into ( ) . unwrap ( )
547
- } ;
487
+ let res = unsafe { libc:: read ( fds[ 0 ] , buf. as_mut_ptr ( ) . cast ( ) , buf. len ( ) as libc:: size_t ) } ;
548
488
assert_eq ! ( res, 2 ) ;
549
489
assert_eq ! ( buf, "de" . as_bytes( ) ) ;
550
490
0 commit comments