objc2_core_foundation/generated/
CFSocket.rs

1//! This file has been automatically generated by `objc2`'s `header-translator`.
2//! DO NOT EDIT
3use core::cell::UnsafeCell;
4use core::ffi::*;
5use core::marker::{PhantomData, PhantomPinned};
6use core::ptr::NonNull;
7#[cfg(feature = "objc2")]
8use objc2::__framework_prelude::*;
9
10use crate::*;
11
12/// [Apple's documentation](https://developer.apple.com/documentation/corefoundation/cfsocket?language=objc)
13#[doc(alias = "CFSocketRef")]
14#[repr(C)]
15pub struct CFSocket {
16    inner: [u8; 0],
17    _p: UnsafeCell<PhantomData<(*const UnsafeCell<()>, PhantomPinned)>>,
18}
19
20cf_type!(
21    unsafe impl CFSocket {}
22);
23#[cfg(feature = "objc2")]
24cf_objc2_type!(
25    unsafe impl RefEncode<"__CFSocket"> for CFSocket {}
26);
27
28/// [Apple's documentation](https://developer.apple.com/documentation/corefoundation/cfsocketerror?language=objc)
29// NS_ENUM
30#[repr(transparent)]
31#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash, PartialOrd, Ord)]
32pub struct CFSocketError(pub CFIndex);
33impl CFSocketError {
34    #[doc(alias = "kCFSocketSuccess")]
35    pub const Success: Self = Self(0);
36    #[doc(alias = "kCFSocketError")]
37    pub const Error: Self = Self(-1);
38    #[doc(alias = "kCFSocketTimeout")]
39    pub const Timeout: Self = Self(-2);
40}
41
42#[cfg(feature = "objc2")]
43unsafe impl Encode for CFSocketError {
44    const ENCODING: Encoding = CFIndex::ENCODING;
45}
46
47#[cfg(feature = "objc2")]
48unsafe impl RefEncode for CFSocketError {
49    const ENCODING_REF: Encoding = Encoding::Pointer(&Self::ENCODING);
50}
51
52/// [Apple's documentation](https://developer.apple.com/documentation/corefoundation/cfsocketsignature?language=objc)
53#[cfg(feature = "CFData")]
54#[repr(C)]
55#[derive(Clone, Copy, Debug, PartialEq)]
56pub struct CFSocketSignature {
57    pub protocolFamily: i32,
58    pub socketType: i32,
59    pub protocol: i32,
60    pub address: *const CFData,
61}
62
63#[cfg(all(feature = "CFData", feature = "objc2"))]
64unsafe impl Encode for CFSocketSignature {
65    const ENCODING: Encoding = Encoding::Struct(
66        "?",
67        &[
68            <i32>::ENCODING,
69            <i32>::ENCODING,
70            <i32>::ENCODING,
71            <*const CFData>::ENCODING,
72        ],
73    );
74}
75
76#[cfg(all(feature = "CFData", feature = "objc2"))]
77unsafe impl RefEncode for CFSocketSignature {
78    const ENCODING_REF: Encoding = Encoding::Pointer(&Self::ENCODING);
79}
80
81/// [Apple's documentation](https://developer.apple.com/documentation/corefoundation/cfsocketcallbacktype?language=objc)
82// NS_OPTIONS
83#[repr(transparent)]
84#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash, PartialOrd, Ord)]
85pub struct CFSocketCallBackType(pub CFOptionFlags);
86bitflags::bitflags! {
87    impl CFSocketCallBackType: CFOptionFlags {
88        #[doc(alias = "kCFSocketNoCallBack")]
89        const NoCallBack = 0;
90        #[doc(alias = "kCFSocketReadCallBack")]
91        const ReadCallBack = 1;
92        #[doc(alias = "kCFSocketAcceptCallBack")]
93        const AcceptCallBack = 2;
94        #[doc(alias = "kCFSocketDataCallBack")]
95        const DataCallBack = 3;
96        #[doc(alias = "kCFSocketConnectCallBack")]
97        const ConnectCallBack = 4;
98        #[doc(alias = "kCFSocketWriteCallBack")]
99        const WriteCallBack = 8;
100    }
101}
102
103#[cfg(feature = "objc2")]
104unsafe impl Encode for CFSocketCallBackType {
105    const ENCODING: Encoding = CFOptionFlags::ENCODING;
106}
107
108#[cfg(feature = "objc2")]
109unsafe impl RefEncode for CFSocketCallBackType {
110    const ENCODING_REF: Encoding = Encoding::Pointer(&Self::ENCODING);
111}
112
113/// [Apple's documentation](https://developer.apple.com/documentation/corefoundation/kcfsocketautomaticallyreenablereadcallback?language=objc)
114pub const kCFSocketAutomaticallyReenableReadCallBack: CFOptionFlags = 1;
115/// [Apple's documentation](https://developer.apple.com/documentation/corefoundation/kcfsocketautomaticallyreenableacceptcallback?language=objc)
116pub const kCFSocketAutomaticallyReenableAcceptCallBack: CFOptionFlags = 2;
117/// [Apple's documentation](https://developer.apple.com/documentation/corefoundation/kcfsocketautomaticallyreenabledatacallback?language=objc)
118pub const kCFSocketAutomaticallyReenableDataCallBack: CFOptionFlags = 3;
119/// [Apple's documentation](https://developer.apple.com/documentation/corefoundation/kcfsocketautomaticallyreenablewritecallback?language=objc)
120pub const kCFSocketAutomaticallyReenableWriteCallBack: CFOptionFlags = 8;
121/// [Apple's documentation](https://developer.apple.com/documentation/corefoundation/kcfsocketleaveerrors?language=objc)
122pub const kCFSocketLeaveErrors: CFOptionFlags = 64;
123/// [Apple's documentation](https://developer.apple.com/documentation/corefoundation/kcfsocketcloseoninvalidate?language=objc)
124pub const kCFSocketCloseOnInvalidate: CFOptionFlags = 128;
125
126/// [Apple's documentation](https://developer.apple.com/documentation/corefoundation/cfsocketcallback?language=objc)
127#[cfg(feature = "CFData")]
128pub type CFSocketCallBack = Option<
129    unsafe extern "C-unwind" fn(
130        *mut CFSocket,
131        CFSocketCallBackType,
132        *const CFData,
133        *const c_void,
134        *mut c_void,
135    ),
136>;
137
138/// [Apple's documentation](https://developer.apple.com/documentation/corefoundation/cfsocketcontext?language=objc)
139#[repr(C)]
140#[allow(unpredictable_function_pointer_comparisons)]
141#[derive(Clone, Copy, Debug, PartialEq)]
142pub struct CFSocketContext {
143    pub version: CFIndex,
144    pub info: *mut c_void,
145    pub retain: Option<unsafe extern "C-unwind" fn(*const c_void) -> *const c_void>,
146    pub release: Option<unsafe extern "C-unwind" fn(*const c_void)>,
147    pub copyDescription: Option<unsafe extern "C-unwind" fn(*const c_void) -> *const CFString>,
148}
149
150#[cfg(feature = "objc2")]
151unsafe impl Encode for CFSocketContext {
152    const ENCODING: Encoding = Encoding::Struct(
153        "?",
154        &[
155            <CFIndex>::ENCODING,
156            <*mut c_void>::ENCODING,
157            <Option<unsafe extern "C-unwind" fn(*const c_void) -> *const c_void>>::ENCODING,
158            <Option<unsafe extern "C-unwind" fn(*const c_void)>>::ENCODING,
159            <Option<unsafe extern "C-unwind" fn(*const c_void) -> *const CFString>>::ENCODING,
160        ],
161    );
162}
163
164#[cfg(feature = "objc2")]
165unsafe impl RefEncode for CFSocketContext {
166    const ENCODING_REF: Encoding = Encoding::Pointer(&Self::ENCODING);
167}
168
169/// [Apple's documentation](https://developer.apple.com/documentation/corefoundation/cfsocketnativehandle?language=objc)
170pub type CFSocketNativeHandle = c_int;
171
172unsafe impl ConcreteType for CFSocket {
173    #[doc(alias = "CFSocketGetTypeID")]
174    #[inline]
175    fn type_id() -> CFTypeID {
176        extern "C-unwind" {
177            fn CFSocketGetTypeID() -> CFTypeID;
178        }
179        unsafe { CFSocketGetTypeID() }
180    }
181}
182
183impl CFSocket {
184    /// # Safety
185    ///
186    /// - `allocator` might not allow `None`.
187    /// - `callout` must be implemented correctly.
188    /// - `context` must be a valid pointer.
189    #[doc(alias = "CFSocketCreate")]
190    #[cfg(feature = "CFData")]
191    #[inline]
192    pub unsafe fn new(
193        allocator: Option<&CFAllocator>,
194        protocol_family: i32,
195        socket_type: i32,
196        protocol: i32,
197        call_back_types: CFOptionFlags,
198        callout: CFSocketCallBack,
199        context: *const CFSocketContext,
200    ) -> Option<CFRetained<CFSocket>> {
201        extern "C-unwind" {
202            fn CFSocketCreate(
203                allocator: Option<&CFAllocator>,
204                protocol_family: i32,
205                socket_type: i32,
206                protocol: i32,
207                call_back_types: CFOptionFlags,
208                callout: CFSocketCallBack,
209                context: *const CFSocketContext,
210            ) -> Option<NonNull<CFSocket>>;
211        }
212        let ret = unsafe {
213            CFSocketCreate(
214                allocator,
215                protocol_family,
216                socket_type,
217                protocol,
218                call_back_types,
219                callout,
220                context,
221            )
222        };
223        ret.map(|ret| unsafe { CFRetained::from_raw(ret) })
224    }
225
226    /// # Safety
227    ///
228    /// - `allocator` might not allow `None`.
229    /// - `callout` must be implemented correctly.
230    /// - `context` must be a valid pointer.
231    #[doc(alias = "CFSocketCreateWithNative")]
232    #[cfg(feature = "CFData")]
233    #[inline]
234    pub unsafe fn with_native(
235        allocator: Option<&CFAllocator>,
236        sock: CFSocketNativeHandle,
237        call_back_types: CFOptionFlags,
238        callout: CFSocketCallBack,
239        context: *const CFSocketContext,
240    ) -> Option<CFRetained<CFSocket>> {
241        extern "C-unwind" {
242            fn CFSocketCreateWithNative(
243                allocator: Option<&CFAllocator>,
244                sock: CFSocketNativeHandle,
245                call_back_types: CFOptionFlags,
246                callout: CFSocketCallBack,
247                context: *const CFSocketContext,
248            ) -> Option<NonNull<CFSocket>>;
249        }
250        let ret =
251            unsafe { CFSocketCreateWithNative(allocator, sock, call_back_types, callout, context) };
252        ret.map(|ret| unsafe { CFRetained::from_raw(ret) })
253    }
254
255    /// # Safety
256    ///
257    /// - `allocator` might not allow `None`.
258    /// - `signature` must be a valid pointer.
259    /// - `callout` must be implemented correctly.
260    /// - `context` must be a valid pointer.
261    #[doc(alias = "CFSocketCreateWithSocketSignature")]
262    #[cfg(feature = "CFData")]
263    #[inline]
264    pub unsafe fn with_socket_signature(
265        allocator: Option<&CFAllocator>,
266        signature: *const CFSocketSignature,
267        call_back_types: CFOptionFlags,
268        callout: CFSocketCallBack,
269        context: *const CFSocketContext,
270    ) -> Option<CFRetained<CFSocket>> {
271        extern "C-unwind" {
272            fn CFSocketCreateWithSocketSignature(
273                allocator: Option<&CFAllocator>,
274                signature: *const CFSocketSignature,
275                call_back_types: CFOptionFlags,
276                callout: CFSocketCallBack,
277                context: *const CFSocketContext,
278            ) -> Option<NonNull<CFSocket>>;
279        }
280        let ret = unsafe {
281            CFSocketCreateWithSocketSignature(
282                allocator,
283                signature,
284                call_back_types,
285                callout,
286                context,
287            )
288        };
289        ret.map(|ret| unsafe { CFRetained::from_raw(ret) })
290    }
291
292    /// # Safety
293    ///
294    /// - `allocator` might not allow `None`.
295    /// - `signature` must be a valid pointer.
296    /// - `callout` must be implemented correctly.
297    /// - `context` must be a valid pointer.
298    #[doc(alias = "CFSocketCreateConnectedToSocketSignature")]
299    #[cfg(all(feature = "CFData", feature = "CFDate"))]
300    #[inline]
301    pub unsafe fn new_connected_to_socket_signature(
302        allocator: Option<&CFAllocator>,
303        signature: *const CFSocketSignature,
304        call_back_types: CFOptionFlags,
305        callout: CFSocketCallBack,
306        context: *const CFSocketContext,
307        timeout: CFTimeInterval,
308    ) -> Option<CFRetained<CFSocket>> {
309        extern "C-unwind" {
310            fn CFSocketCreateConnectedToSocketSignature(
311                allocator: Option<&CFAllocator>,
312                signature: *const CFSocketSignature,
313                call_back_types: CFOptionFlags,
314                callout: CFSocketCallBack,
315                context: *const CFSocketContext,
316                timeout: CFTimeInterval,
317            ) -> Option<NonNull<CFSocket>>;
318        }
319        let ret = unsafe {
320            CFSocketCreateConnectedToSocketSignature(
321                allocator,
322                signature,
323                call_back_types,
324                callout,
325                context,
326                timeout,
327            )
328        };
329        ret.map(|ret| unsafe { CFRetained::from_raw(ret) })
330    }
331
332    #[doc(alias = "CFSocketSetAddress")]
333    #[cfg(feature = "CFData")]
334    #[inline]
335    pub fn set_address(&self, address: Option<&CFData>) -> CFSocketError {
336        extern "C-unwind" {
337            fn CFSocketSetAddress(s: &CFSocket, address: Option<&CFData>) -> CFSocketError;
338        }
339        unsafe { CFSocketSetAddress(self, address) }
340    }
341
342    #[doc(alias = "CFSocketConnectToAddress")]
343    #[cfg(all(feature = "CFData", feature = "CFDate"))]
344    #[inline]
345    pub fn connect_to_address(
346        &self,
347        address: Option<&CFData>,
348        timeout: CFTimeInterval,
349    ) -> CFSocketError {
350        extern "C-unwind" {
351            fn CFSocketConnectToAddress(
352                s: &CFSocket,
353                address: Option<&CFData>,
354                timeout: CFTimeInterval,
355            ) -> CFSocketError;
356        }
357        unsafe { CFSocketConnectToAddress(self, address, timeout) }
358    }
359
360    #[doc(alias = "CFSocketInvalidate")]
361    #[inline]
362    pub fn invalidate(&self) {
363        extern "C-unwind" {
364            fn CFSocketInvalidate(s: &CFSocket);
365        }
366        unsafe { CFSocketInvalidate(self) }
367    }
368
369    #[doc(alias = "CFSocketIsValid")]
370    #[inline]
371    pub fn is_valid(&self) -> bool {
372        extern "C-unwind" {
373            fn CFSocketIsValid(s: &CFSocket) -> Boolean;
374        }
375        let ret = unsafe { CFSocketIsValid(self) };
376        ret != 0
377    }
378
379    #[doc(alias = "CFSocketCopyAddress")]
380    #[cfg(feature = "CFData")]
381    #[inline]
382    pub fn address(&self) -> Option<CFRetained<CFData>> {
383        extern "C-unwind" {
384            fn CFSocketCopyAddress(s: &CFSocket) -> Option<NonNull<CFData>>;
385        }
386        let ret = unsafe { CFSocketCopyAddress(self) };
387        ret.map(|ret| unsafe { CFRetained::from_raw(ret) })
388    }
389
390    #[doc(alias = "CFSocketCopyPeerAddress")]
391    #[cfg(feature = "CFData")]
392    #[inline]
393    pub fn peer_address(&self) -> Option<CFRetained<CFData>> {
394        extern "C-unwind" {
395            fn CFSocketCopyPeerAddress(s: &CFSocket) -> Option<NonNull<CFData>>;
396        }
397        let ret = unsafe { CFSocketCopyPeerAddress(self) };
398        ret.map(|ret| unsafe { CFRetained::from_raw(ret) })
399    }
400
401    /// # Safety
402    ///
403    /// `context` must be a valid pointer.
404    #[doc(alias = "CFSocketGetContext")]
405    #[inline]
406    pub unsafe fn context(&self, context: *mut CFSocketContext) {
407        extern "C-unwind" {
408            fn CFSocketGetContext(s: &CFSocket, context: *mut CFSocketContext);
409        }
410        unsafe { CFSocketGetContext(self, context) }
411    }
412
413    #[doc(alias = "CFSocketGetNative")]
414    #[inline]
415    pub fn native(&self) -> CFSocketNativeHandle {
416        extern "C-unwind" {
417            fn CFSocketGetNative(s: &CFSocket) -> CFSocketNativeHandle;
418        }
419        unsafe { CFSocketGetNative(self) }
420    }
421
422    #[doc(alias = "CFSocketCreateRunLoopSource")]
423    #[cfg(feature = "CFRunLoop")]
424    #[inline]
425    pub fn new_run_loop_source(
426        allocator: Option<&CFAllocator>,
427        s: Option<&CFSocket>,
428        order: CFIndex,
429    ) -> Option<CFRetained<CFRunLoopSource>> {
430        extern "C-unwind" {
431            fn CFSocketCreateRunLoopSource(
432                allocator: Option<&CFAllocator>,
433                s: Option<&CFSocket>,
434                order: CFIndex,
435            ) -> Option<NonNull<CFRunLoopSource>>;
436        }
437        let ret = unsafe { CFSocketCreateRunLoopSource(allocator, s, order) };
438        ret.map(|ret| unsafe { CFRetained::from_raw(ret) })
439    }
440
441    #[doc(alias = "CFSocketGetSocketFlags")]
442    #[inline]
443    pub fn socket_flags(&self) -> CFOptionFlags {
444        extern "C-unwind" {
445            fn CFSocketGetSocketFlags(s: &CFSocket) -> CFOptionFlags;
446        }
447        unsafe { CFSocketGetSocketFlags(self) }
448    }
449
450    #[doc(alias = "CFSocketSetSocketFlags")]
451    #[inline]
452    pub fn set_socket_flags(&self, flags: CFOptionFlags) {
453        extern "C-unwind" {
454            fn CFSocketSetSocketFlags(s: &CFSocket, flags: CFOptionFlags);
455        }
456        unsafe { CFSocketSetSocketFlags(self, flags) }
457    }
458
459    #[doc(alias = "CFSocketDisableCallBacks")]
460    #[inline]
461    pub fn disable_call_backs(&self, call_back_types: CFOptionFlags) {
462        extern "C-unwind" {
463            fn CFSocketDisableCallBacks(s: &CFSocket, call_back_types: CFOptionFlags);
464        }
465        unsafe { CFSocketDisableCallBacks(self, call_back_types) }
466    }
467
468    #[doc(alias = "CFSocketEnableCallBacks")]
469    #[inline]
470    pub fn enable_call_backs(&self, call_back_types: CFOptionFlags) {
471        extern "C-unwind" {
472            fn CFSocketEnableCallBacks(s: &CFSocket, call_back_types: CFOptionFlags);
473        }
474        unsafe { CFSocketEnableCallBacks(self, call_back_types) }
475    }
476
477    #[doc(alias = "CFSocketSendData")]
478    #[cfg(all(feature = "CFData", feature = "CFDate"))]
479    #[inline]
480    pub fn send_data(
481        &self,
482        address: Option<&CFData>,
483        data: Option<&CFData>,
484        timeout: CFTimeInterval,
485    ) -> CFSocketError {
486        extern "C-unwind" {
487            fn CFSocketSendData(
488                s: &CFSocket,
489                address: Option<&CFData>,
490                data: Option<&CFData>,
491                timeout: CFTimeInterval,
492            ) -> CFSocketError;
493        }
494        unsafe { CFSocketSendData(self, address, data, timeout) }
495    }
496
497    /// # Safety
498    ///
499    /// - `name_server_signature` must be a valid pointer.
500    /// - `name` might not allow `None`.
501    /// - `value` should be of the correct type.
502    /// - `value` might not allow `None`.
503    #[doc(alias = "CFSocketRegisterValue")]
504    #[cfg(all(feature = "CFData", feature = "CFDate"))]
505    #[inline]
506    pub unsafe fn register_value(
507        name_server_signature: *const CFSocketSignature,
508        timeout: CFTimeInterval,
509        name: Option<&CFString>,
510        value: Option<&CFPropertyList>,
511    ) -> CFSocketError {
512        extern "C-unwind" {
513            fn CFSocketRegisterValue(
514                name_server_signature: *const CFSocketSignature,
515                timeout: CFTimeInterval,
516                name: Option<&CFString>,
517                value: Option<&CFPropertyList>,
518            ) -> CFSocketError;
519        }
520        unsafe { CFSocketRegisterValue(name_server_signature, timeout, name, value) }
521    }
522
523    /// # Safety
524    ///
525    /// - `name_server_signature` must be a valid pointer.
526    /// - `name` might not allow `None`.
527    /// - `value` must be a valid pointer.
528    /// - `name_server_address` must be a valid pointer.
529    #[doc(alias = "CFSocketCopyRegisteredValue")]
530    #[cfg(all(feature = "CFData", feature = "CFDate"))]
531    #[inline]
532    pub unsafe fn copy_registered_value(
533        name_server_signature: *const CFSocketSignature,
534        timeout: CFTimeInterval,
535        name: Option<&CFString>,
536        value: *mut *const CFPropertyList,
537        name_server_address: *mut *const CFData,
538    ) -> CFSocketError {
539        extern "C-unwind" {
540            fn CFSocketCopyRegisteredValue(
541                name_server_signature: *const CFSocketSignature,
542                timeout: CFTimeInterval,
543                name: Option<&CFString>,
544                value: *mut *const CFPropertyList,
545                name_server_address: *mut *const CFData,
546            ) -> CFSocketError;
547        }
548        unsafe {
549            CFSocketCopyRegisteredValue(
550                name_server_signature,
551                timeout,
552                name,
553                value,
554                name_server_address,
555            )
556        }
557    }
558
559    /// # Safety
560    ///
561    /// - `name_server_signature` must be a valid pointer.
562    /// - `name` might not allow `None`.
563    /// - `signature` must be a valid pointer.
564    #[doc(alias = "CFSocketRegisterSocketSignature")]
565    #[cfg(all(feature = "CFData", feature = "CFDate"))]
566    #[inline]
567    pub unsafe fn register_socket_signature(
568        name_server_signature: *const CFSocketSignature,
569        timeout: CFTimeInterval,
570        name: Option<&CFString>,
571        signature: *const CFSocketSignature,
572    ) -> CFSocketError {
573        extern "C-unwind" {
574            fn CFSocketRegisterSocketSignature(
575                name_server_signature: *const CFSocketSignature,
576                timeout: CFTimeInterval,
577                name: Option<&CFString>,
578                signature: *const CFSocketSignature,
579            ) -> CFSocketError;
580        }
581        unsafe { CFSocketRegisterSocketSignature(name_server_signature, timeout, name, signature) }
582    }
583
584    /// # Safety
585    ///
586    /// - `name_server_signature` must be a valid pointer.
587    /// - `name` might not allow `None`.
588    /// - `signature` must be a valid pointer.
589    /// - `name_server_address` must be a valid pointer.
590    #[doc(alias = "CFSocketCopyRegisteredSocketSignature")]
591    #[cfg(all(feature = "CFData", feature = "CFDate"))]
592    #[inline]
593    pub unsafe fn copy_registered_socket_signature(
594        name_server_signature: *const CFSocketSignature,
595        timeout: CFTimeInterval,
596        name: Option<&CFString>,
597        signature: *mut CFSocketSignature,
598        name_server_address: *mut *const CFData,
599    ) -> CFSocketError {
600        extern "C-unwind" {
601            fn CFSocketCopyRegisteredSocketSignature(
602                name_server_signature: *const CFSocketSignature,
603                timeout: CFTimeInterval,
604                name: Option<&CFString>,
605                signature: *mut CFSocketSignature,
606                name_server_address: *mut *const CFData,
607            ) -> CFSocketError;
608        }
609        unsafe {
610            CFSocketCopyRegisteredSocketSignature(
611                name_server_signature,
612                timeout,
613                name,
614                signature,
615                name_server_address,
616            )
617        }
618    }
619
620    /// # Safety
621    ///
622    /// - `name_server_signature` must be a valid pointer.
623    /// - `name` might not allow `None`.
624    #[doc(alias = "CFSocketUnregister")]
625    #[cfg(all(feature = "CFData", feature = "CFDate"))]
626    #[inline]
627    pub unsafe fn unregister(
628        name_server_signature: *const CFSocketSignature,
629        timeout: CFTimeInterval,
630        name: Option<&CFString>,
631    ) -> CFSocketError {
632        extern "C-unwind" {
633            fn CFSocketUnregister(
634                name_server_signature: *const CFSocketSignature,
635                timeout: CFTimeInterval,
636                name: Option<&CFString>,
637            ) -> CFSocketError;
638        }
639        unsafe { CFSocketUnregister(name_server_signature, timeout, name) }
640    }
641
642    #[doc(alias = "CFSocketSetDefaultNameRegistryPortNumber")]
643    #[inline]
644    pub fn set_default_name_registry_port_number(port: u16) {
645        extern "C-unwind" {
646            fn CFSocketSetDefaultNameRegistryPortNumber(port: u16);
647        }
648        unsafe { CFSocketSetDefaultNameRegistryPortNumber(port) }
649    }
650
651    #[doc(alias = "CFSocketGetDefaultNameRegistryPortNumber")]
652    #[inline]
653    pub fn default_name_registry_port_number() -> u16 {
654        extern "C-unwind" {
655            fn CFSocketGetDefaultNameRegistryPortNumber() -> u16;
656        }
657        unsafe { CFSocketGetDefaultNameRegistryPortNumber() }
658    }
659}
660
661extern "C" {
662    /// [Apple's documentation](https://developer.apple.com/documentation/corefoundation/kcfsocketcommandkey?language=objc)
663    pub static kCFSocketCommandKey: Option<&'static CFString>;
664}
665
666extern "C" {
667    /// [Apple's documentation](https://developer.apple.com/documentation/corefoundation/kcfsocketnamekey?language=objc)
668    pub static kCFSocketNameKey: Option<&'static CFString>;
669}
670
671extern "C" {
672    /// [Apple's documentation](https://developer.apple.com/documentation/corefoundation/kcfsocketvaluekey?language=objc)
673    pub static kCFSocketValueKey: Option<&'static CFString>;
674}
675
676extern "C" {
677    /// [Apple's documentation](https://developer.apple.com/documentation/corefoundation/kcfsocketresultkey?language=objc)
678    pub static kCFSocketResultKey: Option<&'static CFString>;
679}
680
681extern "C" {
682    /// [Apple's documentation](https://developer.apple.com/documentation/corefoundation/kcfsocketerrorkey?language=objc)
683    pub static kCFSocketErrorKey: Option<&'static CFString>;
684}
685
686extern "C" {
687    /// [Apple's documentation](https://developer.apple.com/documentation/corefoundation/kcfsocketregistercommand?language=objc)
688    pub static kCFSocketRegisterCommand: Option<&'static CFString>;
689}
690
691extern "C" {
692    /// [Apple's documentation](https://developer.apple.com/documentation/corefoundation/kcfsocketretrievecommand?language=objc)
693    pub static kCFSocketRetrieveCommand: Option<&'static CFString>;
694}
695
696#[cfg(feature = "CFData")]
697#[deprecated = "renamed to `CFSocket::new`"]
698#[inline]
699pub unsafe extern "C-unwind" fn CFSocketCreate(
700    allocator: Option<&CFAllocator>,
701    protocol_family: i32,
702    socket_type: i32,
703    protocol: i32,
704    call_back_types: CFOptionFlags,
705    callout: CFSocketCallBack,
706    context: *const CFSocketContext,
707) -> Option<CFRetained<CFSocket>> {
708    extern "C-unwind" {
709        fn CFSocketCreate(
710            allocator: Option<&CFAllocator>,
711            protocol_family: i32,
712            socket_type: i32,
713            protocol: i32,
714            call_back_types: CFOptionFlags,
715            callout: CFSocketCallBack,
716            context: *const CFSocketContext,
717        ) -> Option<NonNull<CFSocket>>;
718    }
719    let ret = unsafe {
720        CFSocketCreate(
721            allocator,
722            protocol_family,
723            socket_type,
724            protocol,
725            call_back_types,
726            callout,
727            context,
728        )
729    };
730    ret.map(|ret| unsafe { CFRetained::from_raw(ret) })
731}
732
733#[cfg(feature = "CFData")]
734#[deprecated = "renamed to `CFSocket::with_native`"]
735#[inline]
736pub unsafe extern "C-unwind" fn CFSocketCreateWithNative(
737    allocator: Option<&CFAllocator>,
738    sock: CFSocketNativeHandle,
739    call_back_types: CFOptionFlags,
740    callout: CFSocketCallBack,
741    context: *const CFSocketContext,
742) -> Option<CFRetained<CFSocket>> {
743    extern "C-unwind" {
744        fn CFSocketCreateWithNative(
745            allocator: Option<&CFAllocator>,
746            sock: CFSocketNativeHandle,
747            call_back_types: CFOptionFlags,
748            callout: CFSocketCallBack,
749            context: *const CFSocketContext,
750        ) -> Option<NonNull<CFSocket>>;
751    }
752    let ret =
753        unsafe { CFSocketCreateWithNative(allocator, sock, call_back_types, callout, context) };
754    ret.map(|ret| unsafe { CFRetained::from_raw(ret) })
755}
756
757#[cfg(feature = "CFData")]
758#[deprecated = "renamed to `CFSocket::with_socket_signature`"]
759#[inline]
760pub unsafe extern "C-unwind" fn CFSocketCreateWithSocketSignature(
761    allocator: Option<&CFAllocator>,
762    signature: *const CFSocketSignature,
763    call_back_types: CFOptionFlags,
764    callout: CFSocketCallBack,
765    context: *const CFSocketContext,
766) -> Option<CFRetained<CFSocket>> {
767    extern "C-unwind" {
768        fn CFSocketCreateWithSocketSignature(
769            allocator: Option<&CFAllocator>,
770            signature: *const CFSocketSignature,
771            call_back_types: CFOptionFlags,
772            callout: CFSocketCallBack,
773            context: *const CFSocketContext,
774        ) -> Option<NonNull<CFSocket>>;
775    }
776    let ret = unsafe {
777        CFSocketCreateWithSocketSignature(allocator, signature, call_back_types, callout, context)
778    };
779    ret.map(|ret| unsafe { CFRetained::from_raw(ret) })
780}
781
782#[cfg(all(feature = "CFData", feature = "CFDate"))]
783#[deprecated = "renamed to `CFSocket::new_connected_to_socket_signature`"]
784#[inline]
785pub unsafe extern "C-unwind" fn CFSocketCreateConnectedToSocketSignature(
786    allocator: Option<&CFAllocator>,
787    signature: *const CFSocketSignature,
788    call_back_types: CFOptionFlags,
789    callout: CFSocketCallBack,
790    context: *const CFSocketContext,
791    timeout: CFTimeInterval,
792) -> Option<CFRetained<CFSocket>> {
793    extern "C-unwind" {
794        fn CFSocketCreateConnectedToSocketSignature(
795            allocator: Option<&CFAllocator>,
796            signature: *const CFSocketSignature,
797            call_back_types: CFOptionFlags,
798            callout: CFSocketCallBack,
799            context: *const CFSocketContext,
800            timeout: CFTimeInterval,
801        ) -> Option<NonNull<CFSocket>>;
802    }
803    let ret = unsafe {
804        CFSocketCreateConnectedToSocketSignature(
805            allocator,
806            signature,
807            call_back_types,
808            callout,
809            context,
810            timeout,
811        )
812    };
813    ret.map(|ret| unsafe { CFRetained::from_raw(ret) })
814}
815
816#[cfg(feature = "CFData")]
817#[deprecated = "renamed to `CFSocket::set_address`"]
818#[inline]
819pub extern "C-unwind" fn CFSocketSetAddress(
820    s: &CFSocket,
821    address: Option<&CFData>,
822) -> CFSocketError {
823    extern "C-unwind" {
824        fn CFSocketSetAddress(s: &CFSocket, address: Option<&CFData>) -> CFSocketError;
825    }
826    unsafe { CFSocketSetAddress(s, address) }
827}
828
829#[cfg(all(feature = "CFData", feature = "CFDate"))]
830#[deprecated = "renamed to `CFSocket::connect_to_address`"]
831#[inline]
832pub extern "C-unwind" fn CFSocketConnectToAddress(
833    s: &CFSocket,
834    address: Option<&CFData>,
835    timeout: CFTimeInterval,
836) -> CFSocketError {
837    extern "C-unwind" {
838        fn CFSocketConnectToAddress(
839            s: &CFSocket,
840            address: Option<&CFData>,
841            timeout: CFTimeInterval,
842        ) -> CFSocketError;
843    }
844    unsafe { CFSocketConnectToAddress(s, address, timeout) }
845}
846
847#[deprecated = "renamed to `CFSocket::invalidate`"]
848#[inline]
849pub extern "C-unwind" fn CFSocketInvalidate(s: &CFSocket) {
850    extern "C-unwind" {
851        fn CFSocketInvalidate(s: &CFSocket);
852    }
853    unsafe { CFSocketInvalidate(s) }
854}
855
856#[deprecated = "renamed to `CFSocket::is_valid`"]
857#[inline]
858pub extern "C-unwind" fn CFSocketIsValid(s: &CFSocket) -> bool {
859    extern "C-unwind" {
860        fn CFSocketIsValid(s: &CFSocket) -> Boolean;
861    }
862    let ret = unsafe { CFSocketIsValid(s) };
863    ret != 0
864}
865
866#[cfg(feature = "CFData")]
867#[deprecated = "renamed to `CFSocket::address`"]
868#[inline]
869pub extern "C-unwind" fn CFSocketCopyAddress(s: &CFSocket) -> Option<CFRetained<CFData>> {
870    extern "C-unwind" {
871        fn CFSocketCopyAddress(s: &CFSocket) -> Option<NonNull<CFData>>;
872    }
873    let ret = unsafe { CFSocketCopyAddress(s) };
874    ret.map(|ret| unsafe { CFRetained::from_raw(ret) })
875}
876
877#[cfg(feature = "CFData")]
878#[deprecated = "renamed to `CFSocket::peer_address`"]
879#[inline]
880pub extern "C-unwind" fn CFSocketCopyPeerAddress(s: &CFSocket) -> Option<CFRetained<CFData>> {
881    extern "C-unwind" {
882        fn CFSocketCopyPeerAddress(s: &CFSocket) -> Option<NonNull<CFData>>;
883    }
884    let ret = unsafe { CFSocketCopyPeerAddress(s) };
885    ret.map(|ret| unsafe { CFRetained::from_raw(ret) })
886}
887
888extern "C-unwind" {
889    #[deprecated = "renamed to `CFSocket::context`"]
890    pub fn CFSocketGetContext(s: &CFSocket, context: *mut CFSocketContext);
891}
892
893#[deprecated = "renamed to `CFSocket::native`"]
894#[inline]
895pub extern "C-unwind" fn CFSocketGetNative(s: &CFSocket) -> CFSocketNativeHandle {
896    extern "C-unwind" {
897        fn CFSocketGetNative(s: &CFSocket) -> CFSocketNativeHandle;
898    }
899    unsafe { CFSocketGetNative(s) }
900}
901
902#[cfg(feature = "CFRunLoop")]
903#[deprecated = "renamed to `CFSocket::new_run_loop_source`"]
904#[inline]
905pub extern "C-unwind" fn CFSocketCreateRunLoopSource(
906    allocator: Option<&CFAllocator>,
907    s: Option<&CFSocket>,
908    order: CFIndex,
909) -> Option<CFRetained<CFRunLoopSource>> {
910    extern "C-unwind" {
911        fn CFSocketCreateRunLoopSource(
912            allocator: Option<&CFAllocator>,
913            s: Option<&CFSocket>,
914            order: CFIndex,
915        ) -> Option<NonNull<CFRunLoopSource>>;
916    }
917    let ret = unsafe { CFSocketCreateRunLoopSource(allocator, s, order) };
918    ret.map(|ret| unsafe { CFRetained::from_raw(ret) })
919}
920
921#[deprecated = "renamed to `CFSocket::socket_flags`"]
922#[inline]
923pub extern "C-unwind" fn CFSocketGetSocketFlags(s: &CFSocket) -> CFOptionFlags {
924    extern "C-unwind" {
925        fn CFSocketGetSocketFlags(s: &CFSocket) -> CFOptionFlags;
926    }
927    unsafe { CFSocketGetSocketFlags(s) }
928}
929
930#[deprecated = "renamed to `CFSocket::set_socket_flags`"]
931#[inline]
932pub extern "C-unwind" fn CFSocketSetSocketFlags(s: &CFSocket, flags: CFOptionFlags) {
933    extern "C-unwind" {
934        fn CFSocketSetSocketFlags(s: &CFSocket, flags: CFOptionFlags);
935    }
936    unsafe { CFSocketSetSocketFlags(s, flags) }
937}
938
939#[deprecated = "renamed to `CFSocket::disable_call_backs`"]
940#[inline]
941pub extern "C-unwind" fn CFSocketDisableCallBacks(s: &CFSocket, call_back_types: CFOptionFlags) {
942    extern "C-unwind" {
943        fn CFSocketDisableCallBacks(s: &CFSocket, call_back_types: CFOptionFlags);
944    }
945    unsafe { CFSocketDisableCallBacks(s, call_back_types) }
946}
947
948#[deprecated = "renamed to `CFSocket::enable_call_backs`"]
949#[inline]
950pub extern "C-unwind" fn CFSocketEnableCallBacks(s: &CFSocket, call_back_types: CFOptionFlags) {
951    extern "C-unwind" {
952        fn CFSocketEnableCallBacks(s: &CFSocket, call_back_types: CFOptionFlags);
953    }
954    unsafe { CFSocketEnableCallBacks(s, call_back_types) }
955}
956
957#[cfg(all(feature = "CFData", feature = "CFDate"))]
958#[deprecated = "renamed to `CFSocket::send_data`"]
959#[inline]
960pub extern "C-unwind" fn CFSocketSendData(
961    s: &CFSocket,
962    address: Option<&CFData>,
963    data: Option<&CFData>,
964    timeout: CFTimeInterval,
965) -> CFSocketError {
966    extern "C-unwind" {
967        fn CFSocketSendData(
968            s: &CFSocket,
969            address: Option<&CFData>,
970            data: Option<&CFData>,
971            timeout: CFTimeInterval,
972        ) -> CFSocketError;
973    }
974    unsafe { CFSocketSendData(s, address, data, timeout) }
975}
976
977extern "C-unwind" {
978    #[cfg(all(feature = "CFData", feature = "CFDate"))]
979    #[deprecated = "renamed to `CFSocket::register_value`"]
980    pub fn CFSocketRegisterValue(
981        name_server_signature: *const CFSocketSignature,
982        timeout: CFTimeInterval,
983        name: Option<&CFString>,
984        value: Option<&CFPropertyList>,
985    ) -> CFSocketError;
986}
987
988extern "C-unwind" {
989    #[cfg(all(feature = "CFData", feature = "CFDate"))]
990    #[deprecated = "renamed to `CFSocket::copy_registered_value`"]
991    pub fn CFSocketCopyRegisteredValue(
992        name_server_signature: *const CFSocketSignature,
993        timeout: CFTimeInterval,
994        name: Option<&CFString>,
995        value: *mut *const CFPropertyList,
996        name_server_address: *mut *const CFData,
997    ) -> CFSocketError;
998}
999
1000extern "C-unwind" {
1001    #[cfg(all(feature = "CFData", feature = "CFDate"))]
1002    #[deprecated = "renamed to `CFSocket::register_socket_signature`"]
1003    pub fn CFSocketRegisterSocketSignature(
1004        name_server_signature: *const CFSocketSignature,
1005        timeout: CFTimeInterval,
1006        name: Option<&CFString>,
1007        signature: *const CFSocketSignature,
1008    ) -> CFSocketError;
1009}
1010
1011extern "C-unwind" {
1012    #[cfg(all(feature = "CFData", feature = "CFDate"))]
1013    #[deprecated = "renamed to `CFSocket::copy_registered_socket_signature`"]
1014    pub fn CFSocketCopyRegisteredSocketSignature(
1015        name_server_signature: *const CFSocketSignature,
1016        timeout: CFTimeInterval,
1017        name: Option<&CFString>,
1018        signature: *mut CFSocketSignature,
1019        name_server_address: *mut *const CFData,
1020    ) -> CFSocketError;
1021}
1022
1023extern "C-unwind" {
1024    #[cfg(all(feature = "CFData", feature = "CFDate"))]
1025    #[deprecated = "renamed to `CFSocket::unregister`"]
1026    pub fn CFSocketUnregister(
1027        name_server_signature: *const CFSocketSignature,
1028        timeout: CFTimeInterval,
1029        name: Option<&CFString>,
1030    ) -> CFSocketError;
1031}
1032
1033#[deprecated = "renamed to `CFSocket::set_default_name_registry_port_number`"]
1034#[inline]
1035pub extern "C-unwind" fn CFSocketSetDefaultNameRegistryPortNumber(port: u16) {
1036    extern "C-unwind" {
1037        fn CFSocketSetDefaultNameRegistryPortNumber(port: u16);
1038    }
1039    unsafe { CFSocketSetDefaultNameRegistryPortNumber(port) }
1040}
1041
1042#[deprecated = "renamed to `CFSocket::default_name_registry_port_number`"]
1043#[inline]
1044pub extern "C-unwind" fn CFSocketGetDefaultNameRegistryPortNumber() -> u16 {
1045    extern "C-unwind" {
1046        fn CFSocketGetDefaultNameRegistryPortNumber() -> u16;
1047    }
1048    unsafe { CFSocketGetDefaultNameRegistryPortNumber() }
1049}