@@ -10,80 +10,66 @@ fn main() {
10
10
11
11
fn test_socketpair ( ) {
12
12
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 ( ) ) } ;
15
14
assert_eq ! ( res, 0 ) ;
16
15
17
16
// Read size == data available in buffer.
18
17
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 ) } ;
20
19
assert_eq ! ( res, 5 ) ;
21
20
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 ) } ;
25
22
assert_eq ! ( res, 5 ) ;
26
23
assert_eq ! ( buf, "abcde" . as_bytes( ) ) ;
27
24
28
25
// Read size > data available in buffer.
29
26
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 ) } ;
31
28
assert_eq ! ( res, 3 ) ;
32
29
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 ) } ;
36
31
assert_eq ! ( res, 3 ) ;
37
32
assert_eq ! ( & buf2[ 0 ..3 ] , "abc" . as_bytes( ) ) ;
38
33
39
34
// Test read and write from another direction.
40
35
// Read size == data available in buffer.
41
36
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 ) } ;
43
38
assert_eq ! ( res, 5 ) ;
44
39
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 ) } ;
48
41
assert_eq ! ( res, 5 ) ;
49
42
assert_eq ! ( buf3, "12345" . as_bytes( ) ) ;
50
43
51
44
// Read size > data available in buffer.
52
45
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 ) } ;
54
47
assert_eq ! ( res, 3 ) ;
55
48
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 ) } ;
59
50
assert_eq ! ( res, 3 ) ;
60
51
assert_eq ! ( & buf4[ 0 ..3 ] , "123" . as_bytes( ) ) ;
61
52
62
53
// 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 ) } ;
64
55
assert_eq ! ( res, 3 ) ;
65
56
unsafe { libc:: close ( fds[ 0 ] ) } ;
66
57
// Reading the other end should return that data, then EOF.
67
58
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 ) } ;
71
60
assert_eq ! ( res, 3 ) ;
72
61
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 ) } ;
76
63
assert_eq ! ( res, 0 ) ; // 0-sized read: EOF.
77
64
// 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 ) } ;
79
66
assert_eq ! ( res, -1 ) ;
80
67
assert_eq ! ( std:: io:: Error :: last_os_error( ) . raw_os_error( ) , Some ( libc:: EPIPE ) ) ;
81
68
}
82
69
83
70
fn test_socketpair_threaded ( ) {
84
71
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 ( ) ) } ;
87
73
assert_eq ! ( res, 0 ) ;
88
74
89
75
let thread1 = thread:: spawn ( move || {
@@ -99,7 +85,7 @@ fn test_socketpair_threaded() {
99
85
// FIXME: we should yield here once blocking is implemented.
100
86
//thread::yield_now();
101
87
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 ) } ;
103
89
assert_eq ! ( res, 5 ) ;
104
90
thread1. join ( ) . unwrap ( ) ;
105
91
@@ -108,16 +94,13 @@ fn test_socketpair_threaded() {
108
94
// FIXME: we should yield here once blocking is implemented.
109
95
//thread::yield_now();
110
96
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 ) } ;
113
98
assert_eq ! ( res, 5 ) ;
114
99
} ) ;
115
100
// FIXME: we should not yield here once blocking is implemented.
116
101
thread:: yield_now ( ) ;
117
102
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 ) } ;
121
104
assert_eq ! ( res, 5 ) ;
122
105
assert_eq ! ( buf, "12345" . as_bytes( ) ) ;
123
106
thread2. join ( ) . unwrap ( ) ;
@@ -126,8 +109,7 @@ fn test_socketpair_threaded() {
126
109
fn test_race ( ) {
127
110
static mut VAL : u8 = 0 ;
128
111
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 ( ) ) } ;
131
113
assert_eq ! ( res, 0 ) ;
132
114
let thread1 = thread:: spawn ( move || {
133
115
let mut buf: [ u8 ; 1 ] = [ 0 ; 1 ] ;
@@ -145,7 +127,7 @@ fn test_race() {
145
127
} ) ;
146
128
unsafe { VAL = 1 } ;
147
129
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 ) } ;
149
131
assert_eq ! ( res, 1 ) ;
150
132
thread:: yield_now ( ) ;
151
133
thread1. join ( ) . unwrap ( ) ;
0 commit comments