@@ -10,80 +10,66 @@ fn main() {
1010
1111fn test_socketpair ( ) {
1212 let mut fds = [ -1 , -1 ] ;
13- let mut res =
14- unsafe { libc:: socketpair ( libc:: AF_UNIX , libc:: SOCK_STREAM , 0 , fds. as_mut_ptr ( ) ) } ;
13+ let res = unsafe { libc:: socketpair ( libc:: AF_UNIX , libc:: SOCK_STREAM , 0 , fds. as_mut_ptr ( ) ) } ;
1514 assert_eq ! ( res, 0 ) ;
1615
1716 // Read size == data available in buffer.
1817 let data = "abcde" . as_bytes ( ) . as_ptr ( ) ;
19- res = unsafe { libc:: write ( fds[ 0 ] , data as * const libc:: c_void , 5 ) . try_into ( ) . unwrap ( ) } ;
18+ let res = unsafe { libc:: write ( fds[ 0 ] , data as * const libc:: c_void , 5 ) } ;
2019 assert_eq ! ( res, 5 ) ;
2120 let mut buf: [ u8 ; 5 ] = [ 0 ; 5 ] ;
22- res = unsafe {
23- libc:: read ( fds[ 1 ] , buf. as_mut_ptr ( ) . cast ( ) , buf. len ( ) as libc:: size_t ) . try_into ( ) . unwrap ( )
24- } ;
21+ let res = unsafe { libc:: read ( fds[ 1 ] , buf. as_mut_ptr ( ) . cast ( ) , buf. len ( ) as libc:: size_t ) } ;
2522 assert_eq ! ( res, 5 ) ;
2623 assert_eq ! ( buf, "abcde" . as_bytes( ) ) ;
2724
2825 // Read size > data available in buffer.
2926 let data = "abc" . as_bytes ( ) . as_ptr ( ) ;
30- res = unsafe { libc:: write ( fds[ 0 ] , data as * const libc:: c_void , 3 ) . try_into ( ) . unwrap ( ) } ;
27+ let res = unsafe { libc:: write ( fds[ 0 ] , data as * const libc:: c_void , 3 ) } ;
3128 assert_eq ! ( res, 3 ) ;
3229 let mut buf2: [ u8 ; 5 ] = [ 0 ; 5 ] ;
33- res = unsafe {
34- libc:: read ( fds[ 1 ] , buf2. as_mut_ptr ( ) . cast ( ) , buf2. len ( ) as libc:: size_t ) . try_into ( ) . unwrap ( )
35- } ;
30+ let res = unsafe { libc:: read ( fds[ 1 ] , buf2. as_mut_ptr ( ) . cast ( ) , buf2. len ( ) as libc:: size_t ) } ;
3631 assert_eq ! ( res, 3 ) ;
3732 assert_eq ! ( & buf2[ 0 ..3 ] , "abc" . as_bytes( ) ) ;
3833
3934 // Test read and write from another direction.
4035 // Read size == data available in buffer.
4136 let data = "12345" . as_bytes ( ) . as_ptr ( ) ;
42- res = unsafe { libc:: write ( fds[ 1 ] , data as * const libc:: c_void , 5 ) . try_into ( ) . unwrap ( ) } ;
37+ let res = unsafe { libc:: write ( fds[ 1 ] , data as * const libc:: c_void , 5 ) } ;
4338 assert_eq ! ( res, 5 ) ;
4439 let mut buf3: [ u8 ; 5 ] = [ 0 ; 5 ] ;
45- res = unsafe {
46- libc:: read ( fds[ 0 ] , buf3. as_mut_ptr ( ) . cast ( ) , buf3. len ( ) as libc:: size_t ) . try_into ( ) . unwrap ( )
47- } ;
40+ let res = unsafe { libc:: read ( fds[ 0 ] , buf3. as_mut_ptr ( ) . cast ( ) , buf3. len ( ) as libc:: size_t ) } ;
4841 assert_eq ! ( res, 5 ) ;
4942 assert_eq ! ( buf3, "12345" . as_bytes( ) ) ;
5043
5144 // Read size > data available in buffer.
5245 let data = "123" . as_bytes ( ) . as_ptr ( ) ;
53- res = unsafe { libc:: write ( fds[ 1 ] , data as * const libc:: c_void , 3 ) . try_into ( ) . unwrap ( ) } ;
46+ let res = unsafe { libc:: write ( fds[ 1 ] , data as * const libc:: c_void , 3 ) } ;
5447 assert_eq ! ( res, 3 ) ;
5548 let mut buf4: [ u8 ; 5 ] = [ 0 ; 5 ] ;
56- res = unsafe {
57- libc:: read ( fds[ 0 ] , buf4. as_mut_ptr ( ) . cast ( ) , buf4. len ( ) as libc:: size_t ) . try_into ( ) . unwrap ( )
58- } ;
49+ let res = unsafe { libc:: read ( fds[ 0 ] , buf4. as_mut_ptr ( ) . cast ( ) , buf4. len ( ) as libc:: size_t ) } ;
5950 assert_eq ! ( res, 3 ) ;
6051 assert_eq ! ( & buf4[ 0 ..3 ] , "123" . as_bytes( ) ) ;
6152
6253 // Test when happens when we close one end, with some data in the buffer.
63- res = unsafe { libc:: write ( fds[ 0 ] , data as * const libc:: c_void , 3 ) . try_into ( ) . unwrap ( ) } ;
54+ let res = unsafe { libc:: write ( fds[ 0 ] , data as * const libc:: c_void , 3 ) } ;
6455 assert_eq ! ( res, 3 ) ;
6556 unsafe { libc:: close ( fds[ 0 ] ) } ;
6657 // Reading the other end should return that data, then EOF.
6758 let mut buf: [ u8 ; 5 ] = [ 0 ; 5 ] ;
68- res = unsafe {
69- libc:: read ( fds[ 1 ] , buf. as_mut_ptr ( ) . cast ( ) , buf. len ( ) as libc:: size_t ) . try_into ( ) . unwrap ( )
70- } ;
59+ let res = unsafe { libc:: read ( fds[ 1 ] , buf. as_mut_ptr ( ) . cast ( ) , buf. len ( ) as libc:: size_t ) } ;
7160 assert_eq ! ( res, 3 ) ;
7261 assert_eq ! ( & buf[ 0 ..3 ] , "123" . as_bytes( ) ) ;
73- res = unsafe {
74- libc:: read ( fds[ 1 ] , buf. as_mut_ptr ( ) . cast ( ) , buf. len ( ) as libc:: size_t ) . try_into ( ) . unwrap ( )
75- } ;
62+ let res = unsafe { libc:: read ( fds[ 1 ] , buf. as_mut_ptr ( ) . cast ( ) , buf. len ( ) as libc:: size_t ) } ;
7663 assert_eq ! ( res, 0 ) ; // 0-sized read: EOF.
7764 // Writing the other end should emit EPIPE.
78- res = unsafe { libc:: write ( fds[ 1 ] , data as * const libc:: c_void , 1 ) . try_into ( ) . unwrap ( ) } ;
65+ let res = unsafe { libc:: write ( fds[ 1 ] , data as * const libc:: c_void , 1 ) } ;
7966 assert_eq ! ( res, -1 ) ;
8067 assert_eq ! ( std:: io:: Error :: last_os_error( ) . raw_os_error( ) , Some ( libc:: EPIPE ) ) ;
8168}
8269
8370fn test_socketpair_threaded ( ) {
8471 let mut fds = [ -1 , -1 ] ;
85- let mut res =
86- unsafe { libc:: socketpair ( libc:: AF_UNIX , libc:: SOCK_STREAM , 0 , fds. as_mut_ptr ( ) ) } ;
72+ let res = unsafe { libc:: socketpair ( libc:: AF_UNIX , libc:: SOCK_STREAM , 0 , fds. as_mut_ptr ( ) ) } ;
8773 assert_eq ! ( res, 0 ) ;
8874
8975 let thread1 = thread:: spawn ( move || {
@@ -99,7 +85,7 @@ fn test_socketpair_threaded() {
9985 // FIXME: we should yield here once blocking is implemented.
10086 //thread::yield_now();
10187 let data = "abcde" . as_bytes ( ) . as_ptr ( ) ;
102- res = unsafe { libc:: write ( fds[ 0 ] , data as * const libc:: c_void , 5 ) . try_into ( ) . unwrap ( ) } ;
88+ let res = unsafe { libc:: write ( fds[ 0 ] , data as * const libc:: c_void , 5 ) } ;
10389 assert_eq ! ( res, 5 ) ;
10490 thread1. join ( ) . unwrap ( ) ;
10591
@@ -108,16 +94,13 @@ fn test_socketpair_threaded() {
10894 // FIXME: we should yield here once blocking is implemented.
10995 //thread::yield_now();
11096 let data = "12345" . as_bytes ( ) . as_ptr ( ) ;
111- let res: i64 =
112- unsafe { libc:: write ( fds[ 1 ] , data as * const libc:: c_void , 5 ) . try_into ( ) . unwrap ( ) } ;
97+ let res = unsafe { libc:: write ( fds[ 1 ] , data as * const libc:: c_void , 5 ) } ;
11398 assert_eq ! ( res, 5 ) ;
11499 } ) ;
115100 // FIXME: we should not yield here once blocking is implemented.
116101 thread:: yield_now ( ) ;
117102 let mut buf: [ u8 ; 5 ] = [ 0 ; 5 ] ;
118- res = unsafe {
119- libc:: read ( fds[ 0 ] , buf. as_mut_ptr ( ) . cast ( ) , buf. len ( ) as libc:: size_t ) . try_into ( ) . unwrap ( )
120- } ;
103+ let res = unsafe { libc:: read ( fds[ 0 ] , buf. as_mut_ptr ( ) . cast ( ) , buf. len ( ) as libc:: size_t ) } ;
121104 assert_eq ! ( res, 5 ) ;
122105 assert_eq ! ( buf, "12345" . as_bytes( ) ) ;
123106 thread2. join ( ) . unwrap ( ) ;
@@ -126,8 +109,7 @@ fn test_socketpair_threaded() {
126109fn test_race ( ) {
127110 static mut VAL : u8 = 0 ;
128111 let mut fds = [ -1 , -1 ] ;
129- let mut res =
130- unsafe { libc:: socketpair ( libc:: AF_UNIX , libc:: SOCK_STREAM , 0 , fds. as_mut_ptr ( ) ) } ;
112+ let res = unsafe { libc:: socketpair ( libc:: AF_UNIX , libc:: SOCK_STREAM , 0 , fds. as_mut_ptr ( ) ) } ;
131113 assert_eq ! ( res, 0 ) ;
132114 let thread1 = thread:: spawn ( move || {
133115 let mut buf: [ u8 ; 1 ] = [ 0 ; 1 ] ;
@@ -145,7 +127,7 @@ fn test_race() {
145127 } ) ;
146128 unsafe { VAL = 1 } ;
147129 let data = "a" . as_bytes ( ) . as_ptr ( ) ;
148- res = unsafe { libc:: write ( fds[ 0 ] , data as * const libc:: c_void , 1 ) . try_into ( ) . unwrap ( ) } ;
130+ let res = unsafe { libc:: write ( fds[ 0 ] , data as * const libc:: c_void , 1 ) } ;
149131 assert_eq ! ( res, 1 ) ;
150132 thread:: yield_now ( ) ;
151133 thread1. join ( ) . unwrap ( ) ;
0 commit comments