@@ -154,26 +154,43 @@ fn set_nonblocking() {
154
154
assert_nonblocking ( & socket, false ) ;
155
155
}
156
156
157
- #[ test]
158
- fn default_flags ( ) {
159
- let socket = Socket :: new ( Domain :: IPV4 , Type :: STREAM , None ) . unwrap ( ) ;
157
+ fn assert_common_flags ( socket : & Socket , expected : bool ) {
160
158
#[ cfg( unix) ]
161
- assert_close_on_exec ( & socket, true ) ;
159
+ assert_close_on_exec ( socket, expected ) ;
162
160
#[ cfg( target_vendor = "apple" ) ]
163
- assert_flag_no_sigpipe ( & socket, true ) ;
161
+ assert_flag_no_sigpipe ( socket, expected ) ;
164
162
#[ cfg( windows) ]
165
- assert_flag_no_inherit ( & socket, true ) ;
163
+ assert_flag_no_inherit ( socket, expected ) ;
166
164
}
167
165
168
166
#[ test]
169
- fn no_default_flags ( ) {
170
- let socket = Socket :: new_raw ( Domain :: IPV4 , Type :: STREAM , None ) . unwrap ( ) ;
171
- #[ cfg( unix) ]
172
- assert_close_on_exec ( & socket, false ) ;
173
- #[ cfg( target_vendor = "apple" ) ]
174
- assert_flag_no_sigpipe ( & socket, false ) ;
175
- #[ cfg( windows) ]
176
- assert_flag_no_inherit ( & socket, false ) ;
167
+ fn common_flags ( ) {
168
+ let listener = Socket :: new ( Domain :: IPV4 , Type :: STREAM , None ) . unwrap ( ) ;
169
+ assert_common_flags ( & listener, true ) ;
170
+
171
+ listener. bind ( & any_ipv4 ( ) ) . unwrap ( ) ;
172
+ listener. listen ( 1 ) . unwrap ( ) ;
173
+
174
+ let client = Socket :: new ( Domain :: IPV4 , Type :: STREAM , None ) . unwrap ( ) ;
175
+ client. connect ( & listener. local_addr ( ) . unwrap ( ) ) . unwrap ( ) ;
176
+
177
+ let accepted = listener. accept ( ) . unwrap ( ) . 0 ;
178
+ assert_common_flags ( & accepted, true ) ;
179
+ }
180
+
181
+ #[ test]
182
+ fn no_common_flags ( ) {
183
+ let listener = Socket :: new_raw ( Domain :: IPV4 , Type :: STREAM , None ) . unwrap ( ) ;
184
+ assert_common_flags ( & listener, false ) ;
185
+
186
+ listener. bind ( & any_ipv4 ( ) ) . unwrap ( ) ;
187
+ listener. listen ( 1 ) . unwrap ( ) ;
188
+
189
+ let client = Socket :: new ( Domain :: IPV4 , Type :: STREAM , None ) . unwrap ( ) ;
190
+ client. connect ( & listener. local_addr ( ) . unwrap ( ) ) . unwrap ( ) ;
191
+
192
+ let accepted = listener. accept_raw ( ) . unwrap ( ) . 0 ;
193
+ assert_common_flags ( & accepted, false ) ;
177
194
}
178
195
179
196
#[ cfg( all(
0 commit comments