@@ -7,7 +7,8 @@ use std::{fs, thread};
77
88fn main ( ) {
99 test_fcntl_f_dupfd ( ) ;
10- test_setfl_getfl ( ) ;
10+ test_socketpair_setfl_getfl ( ) ;
11+ test_pipe_setfl_getfl ( ) ;
1112 test_setfl_getfl_threaded ( ) ;
1213}
1314
@@ -58,6 +59,33 @@ fn test_socketpair_setfl_getfl() {
5859 assert_eq ! ( res, libc:: O_RDWR ) ;
5960}
6061
62+
63+ fn test_pipe_setfl_getfl ( ) {
64+
65+ let mut fds = [ -1 , -1 ] ;
66+ let res = unsafe { libc:: pipe ( fds. as_mut_ptr ( ) ) } ;
67+ assert_eq ! ( res, 0 ) ;
68+
69+ // Test if both sides have O_RDWR.
70+ let res = unsafe { libc:: fcntl ( fds[ 0 ] , libc:: F_GETFL ) } ;
71+ assert_eq ! ( res, libc:: O_RDONLY ) ;
72+ let res = unsafe { libc:: fcntl ( fds[ 1 ] , libc:: F_GETFL ) } ;
73+ assert_eq ! ( res, libc:: O_WRONLY ) ;
74+
75+ // Add the O_NONBLOCK flag with setfl.
76+ let res = unsafe { libc:: fcntl ( fds[ 0 ] , libc:: F_SETFL , libc:: O_NONBLOCK ) } ;
77+ assert_eq ! ( res, 0 ) ;
78+
79+ // Test if the O_NONBLOCK flag is successfully added.
80+ let new_flag = libc:: O_RDONLY | libc:: O_NONBLOCK ;
81+ let res = unsafe { libc:: fcntl ( fds[ 0 ] , libc:: F_GETFL ) } ;
82+ assert_eq ! ( res, new_flag) ;
83+
84+ // THe other side remains unchanged.
85+ let res = unsafe { libc:: fcntl ( fds[ 1 ] , libc:: F_GETFL ) } ;
86+ assert_eq ! ( res, libc:: O_WRONLY ) ;
87+ }
88+
6189/// Test the behaviour of setfl/getfl when a fd is blocking.
6290/// The expected execution is:
6391/// 1. Main thread blocks on fds[0] `read`.
0 commit comments