@@ -134,12 +134,12 @@ impl SCNetworkService {
134
134
. iter ( )
135
135
. map ( |item| item. downcast :: < SCNetworkService > ( ) . unwrap ( ) )
136
136
. collect :: < Vec < SCNetworkService > > ( )
137
-
137
+
138
138
139
139
// let array: CFArray<SCNetworkService> = unsafe {
140
140
// CFArray::wrap_under_get_rule(SCNetworkServiceCopyAll(prefs.as_concrete_TypeRef()))
141
141
// };
142
-
142
+
143
143
// array
144
144
// .iter()
145
145
// .map(|item| item.as_CFType().downcast::<SCNetworkService>().unwrap())
@@ -149,12 +149,17 @@ impl SCNetworkService {
149
149
/// Returns the user-specified ordering of network services within the specified
150
150
/// preferences.
151
151
pub fn list_order ( prefs : & SCPreferences ) -> Vec < SCNetworkService > {
152
- let netset = unsafe { SCNetworkSetCopyCurrent ( prefs . as_concrete_TypeRef ( ) ) } ;
152
+ let mut services = Vec :: new ( ) ;
153
153
154
- let array: CFArray < CFType > =
155
- unsafe { CFArray :: wrap_under_get_rule ( SCNetworkSetGetServiceOrder ( netset) ) } ;
154
+ let netset = unsafe { SCNetworkSetCopyCurrent ( prefs. as_concrete_TypeRef ( ) ) } ;
156
155
157
- let mut services = Vec :: new ( ) ;
156
+ let array: CFArray < CFType > = unsafe {
157
+ let arr_ref = SCNetworkSetGetServiceOrder ( netset) ;
158
+ if arr_ref. is_null ( ) {
159
+ return services;
160
+ }
161
+ CFArray :: wrap_under_get_rule ( arr_ref)
162
+ } ;
158
163
159
164
for item in array. iter ( ) {
160
165
if let Some ( id) = item. downcast :: < CFString > ( ) {
@@ -416,7 +421,7 @@ impl fmt::Debug for SCNetworkInterface {
416
421
}
417
422
418
423
419
- #[ test]
424
+ #[ cfg ( all ( feature = "nightly" , test) ) ]
420
425
fn test_network_service ( ) {
421
426
use core_foundation:: base:: kCFAllocatorDefault;
422
427
@@ -426,11 +431,11 @@ fn test_network_service() {
426
431
for network_service in list. iter ( ) {
427
432
let network_service_id = network_service. id ( ) ;
428
433
let res = SCNetworkService :: from_id ( & prefs, & network_service_id) ;
429
-
434
+
430
435
assert ! ( res. is_some( ) ) ;
431
436
let res = res. unwrap ( ) ;
432
-
437
+
433
438
assert_eq ! ( res. id( ) , network_service. id( ) ) ;
434
439
assert_eq ! ( res. name( ) , network_service. name( ) ) ;
435
440
}
436
- }
441
+ }
0 commit comments