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#[repr(C)]
14pub struct CFSocket {
15    inner: [u8; 0],
16    _p: UnsafeCell<PhantomData<(*const UnsafeCell<()>, PhantomPinned)>>,
17}
18
19cf_type!(
20    #[encoding_name = "__CFSocket"]
21    unsafe impl CFSocket {}
22);
23
24/// [Apple's documentation](https://developer.apple.com/documentation/corefoundation/cfsocketerror?language=objc)
25// NS_ENUM
26#[cfg(feature = "CFBase")]
27#[repr(transparent)]
28#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash, PartialOrd, Ord)]
29pub struct CFSocketError(pub CFIndex);
30#[cfg(feature = "CFBase")]
31impl CFSocketError {
32    #[doc(alias = "kCFSocketSuccess")]
33    pub const Success: Self = Self(0);
34    #[doc(alias = "kCFSocketError")]
35    pub const Error: Self = Self(-1);
36    #[doc(alias = "kCFSocketTimeout")]
37    pub const Timeout: Self = Self(-2);
38}
39
40#[cfg(all(feature = "CFBase", feature = "objc2"))]
41unsafe impl Encode for CFSocketError {
42    const ENCODING: Encoding = CFIndex::ENCODING;
43}
44
45#[cfg(all(feature = "CFBase", feature = "objc2"))]
46unsafe impl RefEncode for CFSocketError {
47    const ENCODING_REF: Encoding = Encoding::Pointer(&Self::ENCODING);
48}
49
50/// [Apple's documentation](https://developer.apple.com/documentation/corefoundation/cfsocketsignature?language=objc)
51#[cfg(feature = "CFData")]
52#[repr(C)]
53#[derive(Clone, Copy, Debug, PartialEq)]
54pub struct CFSocketSignature {
55    pub protocolFamily: i32,
56    pub socketType: i32,
57    pub protocol: i32,
58    pub address: *const CFData,
59}
60
61#[cfg(all(feature = "CFData", feature = "objc2"))]
62unsafe impl Encode for CFSocketSignature {
63    const ENCODING: Encoding = Encoding::Struct(
64        "?",
65        &[
66            <i32>::ENCODING,
67            <i32>::ENCODING,
68            <i32>::ENCODING,
69            <*const CFData>::ENCODING,
70        ],
71    );
72}
73
74#[cfg(all(feature = "CFData", feature = "objc2"))]
75unsafe impl RefEncode for CFSocketSignature {
76    const ENCODING_REF: Encoding = Encoding::Pointer(&Self::ENCODING);
77}
78
79/// [Apple's documentation](https://developer.apple.com/documentation/corefoundation/cfsocketcallbacktype?language=objc)
80// NS_OPTIONS
81#[cfg(feature = "CFBase")]
82#[repr(transparent)]
83#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash, PartialOrd, Ord)]
84pub struct CFSocketCallBackType(pub CFOptionFlags);
85#[cfg(feature = "CFBase")]
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(all(feature = "CFBase", feature = "objc2"))]
104unsafe impl Encode for CFSocketCallBackType {
105    const ENCODING: Encoding = CFOptionFlags::ENCODING;
106}
107
108#[cfg(all(feature = "CFBase", 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)
114#[cfg(feature = "CFBase")]
115pub const kCFSocketAutomaticallyReenableReadCallBack: CFOptionFlags = 1;
116/// [Apple's documentation](https://developer.apple.com/documentation/corefoundation/kcfsocketautomaticallyreenableacceptcallback?language=objc)
117#[cfg(feature = "CFBase")]
118pub const kCFSocketAutomaticallyReenableAcceptCallBack: CFOptionFlags = 2;
119/// [Apple's documentation](https://developer.apple.com/documentation/corefoundation/kcfsocketautomaticallyreenabledatacallback?language=objc)
120#[cfg(feature = "CFBase")]
121pub const kCFSocketAutomaticallyReenableDataCallBack: CFOptionFlags = 3;
122/// [Apple's documentation](https://developer.apple.com/documentation/corefoundation/kcfsocketautomaticallyreenablewritecallback?language=objc)
123#[cfg(feature = "CFBase")]
124pub const kCFSocketAutomaticallyReenableWriteCallBack: CFOptionFlags = 8;
125/// [Apple's documentation](https://developer.apple.com/documentation/corefoundation/kcfsocketleaveerrors?language=objc)
126#[cfg(feature = "CFBase")]
127pub const kCFSocketLeaveErrors: CFOptionFlags = 64;
128/// [Apple's documentation](https://developer.apple.com/documentation/corefoundation/kcfsocketcloseoninvalidate?language=objc)
129#[cfg(feature = "CFBase")]
130pub const kCFSocketCloseOnInvalidate: CFOptionFlags = 128;
131
132/// [Apple's documentation](https://developer.apple.com/documentation/corefoundation/cfsocketcallback?language=objc)
133#[cfg(all(feature = "CFBase", feature = "CFData"))]
134pub type CFSocketCallBack = Option<
135    unsafe extern "C-unwind" fn(
136        *mut CFSocket,
137        CFSocketCallBackType,
138        *const CFData,
139        *const c_void,
140        *mut c_void,
141    ),
142>;
143
144/// [Apple's documentation](https://developer.apple.com/documentation/corefoundation/cfsocketcontext?language=objc)
145#[cfg(feature = "CFBase")]
146#[repr(C)]
147#[derive(Clone, Copy, Debug, PartialEq)]
148pub struct CFSocketContext {
149    pub version: CFIndex,
150    pub info: *mut c_void,
151    pub retain: Option<unsafe extern "C-unwind" fn(*const c_void) -> *const c_void>,
152    pub release: Option<unsafe extern "C-unwind" fn(*const c_void)>,
153    pub copyDescription: Option<unsafe extern "C-unwind" fn(*const c_void) -> *const CFString>,
154}
155
156#[cfg(all(feature = "CFBase", feature = "objc2"))]
157unsafe impl Encode for CFSocketContext {
158    const ENCODING: Encoding = Encoding::Struct(
159        "?",
160        &[
161            <CFIndex>::ENCODING,
162            <*mut c_void>::ENCODING,
163            <Option<unsafe extern "C-unwind" fn(*const c_void) -> *const c_void>>::ENCODING,
164            <Option<unsafe extern "C-unwind" fn(*const c_void)>>::ENCODING,
165            <Option<unsafe extern "C-unwind" fn(*const c_void) -> *const CFString>>::ENCODING,
166        ],
167    );
168}
169
170#[cfg(all(feature = "CFBase", feature = "objc2"))]
171unsafe impl RefEncode for CFSocketContext {
172    const ENCODING_REF: Encoding = Encoding::Pointer(&Self::ENCODING);
173}
174
175/// [Apple's documentation](https://developer.apple.com/documentation/corefoundation/cfsocketnativehandle?language=objc)
176pub type CFSocketNativeHandle = c_int;
177
178#[cfg(feature = "CFBase")]
179unsafe impl ConcreteType for CFSocket {
180    #[doc(alias = "CFSocketGetTypeID")]
181    #[inline]
182    fn type_id() -> CFTypeID {
183        extern "C-unwind" {
184            fn CFSocketGetTypeID() -> CFTypeID;
185        }
186        unsafe { CFSocketGetTypeID() }
187    }
188}
189
190#[cfg(all(feature = "CFBase", feature = "CFData"))]
191#[inline]
192pub unsafe extern "C-unwind" fn CFSocketCreate(
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#[cfg(all(feature = "CFBase", feature = "CFData"))]
227#[inline]
228pub unsafe extern "C-unwind" fn CFSocketCreateWithNative(
229    allocator: Option<&CFAllocator>,
230    sock: CFSocketNativeHandle,
231    call_back_types: CFOptionFlags,
232    callout: CFSocketCallBack,
233    context: *const CFSocketContext,
234) -> Option<CFRetained<CFSocket>> {
235    extern "C-unwind" {
236        fn CFSocketCreateWithNative(
237            allocator: Option<&CFAllocator>,
238            sock: CFSocketNativeHandle,
239            call_back_types: CFOptionFlags,
240            callout: CFSocketCallBack,
241            context: *const CFSocketContext,
242        ) -> Option<NonNull<CFSocket>>;
243    }
244    let ret =
245        unsafe { CFSocketCreateWithNative(allocator, sock, call_back_types, callout, context) };
246    ret.map(|ret| unsafe { CFRetained::from_raw(ret) })
247}
248
249#[cfg(all(feature = "CFBase", feature = "CFData"))]
250#[inline]
251pub unsafe extern "C-unwind" fn CFSocketCreateWithSocketSignature(
252    allocator: Option<&CFAllocator>,
253    signature: *const CFSocketSignature,
254    call_back_types: CFOptionFlags,
255    callout: CFSocketCallBack,
256    context: *const CFSocketContext,
257) -> Option<CFRetained<CFSocket>> {
258    extern "C-unwind" {
259        fn CFSocketCreateWithSocketSignature(
260            allocator: Option<&CFAllocator>,
261            signature: *const CFSocketSignature,
262            call_back_types: CFOptionFlags,
263            callout: CFSocketCallBack,
264            context: *const CFSocketContext,
265        ) -> Option<NonNull<CFSocket>>;
266    }
267    let ret = unsafe {
268        CFSocketCreateWithSocketSignature(allocator, signature, call_back_types, callout, context)
269    };
270    ret.map(|ret| unsafe { CFRetained::from_raw(ret) })
271}
272
273#[cfg(all(feature = "CFBase", feature = "CFData", feature = "CFDate"))]
274#[inline]
275pub unsafe extern "C-unwind" fn CFSocketCreateConnectedToSocketSignature(
276    allocator: Option<&CFAllocator>,
277    signature: *const CFSocketSignature,
278    call_back_types: CFOptionFlags,
279    callout: CFSocketCallBack,
280    context: *const CFSocketContext,
281    timeout: CFTimeInterval,
282) -> Option<CFRetained<CFSocket>> {
283    extern "C-unwind" {
284        fn CFSocketCreateConnectedToSocketSignature(
285            allocator: Option<&CFAllocator>,
286            signature: *const CFSocketSignature,
287            call_back_types: CFOptionFlags,
288            callout: CFSocketCallBack,
289            context: *const CFSocketContext,
290            timeout: CFTimeInterval,
291        ) -> Option<NonNull<CFSocket>>;
292    }
293    let ret = unsafe {
294        CFSocketCreateConnectedToSocketSignature(
295            allocator,
296            signature,
297            call_back_types,
298            callout,
299            context,
300            timeout,
301        )
302    };
303    ret.map(|ret| unsafe { CFRetained::from_raw(ret) })
304}
305
306extern "C-unwind" {
307    #[cfg(all(feature = "CFBase", feature = "CFData"))]
308    pub fn CFSocketSetAddress(s: &CFSocket, address: Option<&CFData>) -> CFSocketError;
309}
310
311extern "C-unwind" {
312    #[cfg(all(feature = "CFBase", feature = "CFData", feature = "CFDate"))]
313    pub fn CFSocketConnectToAddress(
314        s: &CFSocket,
315        address: Option<&CFData>,
316        timeout: CFTimeInterval,
317    ) -> CFSocketError;
318}
319
320extern "C-unwind" {
321    pub fn CFSocketInvalidate(s: &CFSocket);
322}
323
324#[inline]
325pub unsafe extern "C-unwind" fn CFSocketIsValid(s: &CFSocket) -> bool {
326    extern "C-unwind" {
327        fn CFSocketIsValid(s: &CFSocket) -> Boolean;
328    }
329    let ret = unsafe { CFSocketIsValid(s) };
330    ret != 0
331}
332
333#[cfg(feature = "CFData")]
334#[inline]
335pub unsafe extern "C-unwind" fn CFSocketCopyAddress(s: &CFSocket) -> Option<CFRetained<CFData>> {
336    extern "C-unwind" {
337        fn CFSocketCopyAddress(s: &CFSocket) -> Option<NonNull<CFData>>;
338    }
339    let ret = unsafe { CFSocketCopyAddress(s) };
340    ret.map(|ret| unsafe { CFRetained::from_raw(ret) })
341}
342
343#[cfg(feature = "CFData")]
344#[inline]
345pub unsafe extern "C-unwind" fn CFSocketCopyPeerAddress(
346    s: &CFSocket,
347) -> Option<CFRetained<CFData>> {
348    extern "C-unwind" {
349        fn CFSocketCopyPeerAddress(s: &CFSocket) -> Option<NonNull<CFData>>;
350    }
351    let ret = unsafe { CFSocketCopyPeerAddress(s) };
352    ret.map(|ret| unsafe { CFRetained::from_raw(ret) })
353}
354
355extern "C-unwind" {
356    #[cfg(feature = "CFBase")]
357    pub fn CFSocketGetContext(s: &CFSocket, context: *mut CFSocketContext);
358}
359
360extern "C-unwind" {
361    pub fn CFSocketGetNative(s: &CFSocket) -> CFSocketNativeHandle;
362}
363
364#[cfg(all(feature = "CFBase", feature = "CFRunLoop"))]
365#[inline]
366pub unsafe extern "C-unwind" fn CFSocketCreateRunLoopSource(
367    allocator: Option<&CFAllocator>,
368    s: Option<&CFSocket>,
369    order: CFIndex,
370) -> Option<CFRetained<CFRunLoopSource>> {
371    extern "C-unwind" {
372        fn CFSocketCreateRunLoopSource(
373            allocator: Option<&CFAllocator>,
374            s: Option<&CFSocket>,
375            order: CFIndex,
376        ) -> Option<NonNull<CFRunLoopSource>>;
377    }
378    let ret = unsafe { CFSocketCreateRunLoopSource(allocator, s, order) };
379    ret.map(|ret| unsafe { CFRetained::from_raw(ret) })
380}
381
382extern "C-unwind" {
383    #[cfg(feature = "CFBase")]
384    pub fn CFSocketGetSocketFlags(s: &CFSocket) -> CFOptionFlags;
385}
386
387extern "C-unwind" {
388    #[cfg(feature = "CFBase")]
389    pub fn CFSocketSetSocketFlags(s: &CFSocket, flags: CFOptionFlags);
390}
391
392extern "C-unwind" {
393    #[cfg(feature = "CFBase")]
394    pub fn CFSocketDisableCallBacks(s: &CFSocket, call_back_types: CFOptionFlags);
395}
396
397extern "C-unwind" {
398    #[cfg(feature = "CFBase")]
399    pub fn CFSocketEnableCallBacks(s: &CFSocket, call_back_types: CFOptionFlags);
400}
401
402extern "C-unwind" {
403    #[cfg(all(feature = "CFBase", feature = "CFData", feature = "CFDate"))]
404    pub fn CFSocketSendData(
405        s: &CFSocket,
406        address: Option<&CFData>,
407        data: Option<&CFData>,
408        timeout: CFTimeInterval,
409    ) -> CFSocketError;
410}
411
412extern "C-unwind" {
413    #[cfg(all(feature = "CFBase", feature = "CFData", feature = "CFDate"))]
414    pub fn CFSocketRegisterValue(
415        name_server_signature: *const CFSocketSignature,
416        timeout: CFTimeInterval,
417        name: Option<&CFString>,
418        value: Option<&CFPropertyList>,
419    ) -> CFSocketError;
420}
421
422extern "C-unwind" {
423    #[cfg(all(feature = "CFBase", feature = "CFData", feature = "CFDate"))]
424    pub fn CFSocketCopyRegisteredValue(
425        name_server_signature: *const CFSocketSignature,
426        timeout: CFTimeInterval,
427        name: Option<&CFString>,
428        value: *mut *const CFPropertyList,
429        name_server_address: *mut *const CFData,
430    ) -> CFSocketError;
431}
432
433extern "C-unwind" {
434    #[cfg(all(feature = "CFBase", feature = "CFData", feature = "CFDate"))]
435    pub fn CFSocketRegisterSocketSignature(
436        name_server_signature: *const CFSocketSignature,
437        timeout: CFTimeInterval,
438        name: Option<&CFString>,
439        signature: *const CFSocketSignature,
440    ) -> CFSocketError;
441}
442
443extern "C-unwind" {
444    #[cfg(all(feature = "CFBase", feature = "CFData", feature = "CFDate"))]
445    pub fn CFSocketCopyRegisteredSocketSignature(
446        name_server_signature: *const CFSocketSignature,
447        timeout: CFTimeInterval,
448        name: Option<&CFString>,
449        signature: *mut CFSocketSignature,
450        name_server_address: *mut *const CFData,
451    ) -> CFSocketError;
452}
453
454extern "C-unwind" {
455    #[cfg(all(feature = "CFBase", feature = "CFData", feature = "CFDate"))]
456    pub fn CFSocketUnregister(
457        name_server_signature: *const CFSocketSignature,
458        timeout: CFTimeInterval,
459        name: Option<&CFString>,
460    ) -> CFSocketError;
461}
462
463extern "C-unwind" {
464    pub fn CFSocketSetDefaultNameRegistryPortNumber(port: u16);
465}
466
467extern "C-unwind" {
468    pub fn CFSocketGetDefaultNameRegistryPortNumber() -> u16;
469}
470
471extern "C" {
472    /// [Apple's documentation](https://developer.apple.com/documentation/corefoundation/kcfsocketcommandkey?language=objc)
473    #[cfg(feature = "CFBase")]
474    pub static kCFSocketCommandKey: Option<&'static CFString>;
475}
476
477extern "C" {
478    /// [Apple's documentation](https://developer.apple.com/documentation/corefoundation/kcfsocketnamekey?language=objc)
479    #[cfg(feature = "CFBase")]
480    pub static kCFSocketNameKey: Option<&'static CFString>;
481}
482
483extern "C" {
484    /// [Apple's documentation](https://developer.apple.com/documentation/corefoundation/kcfsocketvaluekey?language=objc)
485    #[cfg(feature = "CFBase")]
486    pub static kCFSocketValueKey: Option<&'static CFString>;
487}
488
489extern "C" {
490    /// [Apple's documentation](https://developer.apple.com/documentation/corefoundation/kcfsocketresultkey?language=objc)
491    #[cfg(feature = "CFBase")]
492    pub static kCFSocketResultKey: Option<&'static CFString>;
493}
494
495extern "C" {
496    /// [Apple's documentation](https://developer.apple.com/documentation/corefoundation/kcfsocketerrorkey?language=objc)
497    #[cfg(feature = "CFBase")]
498    pub static kCFSocketErrorKey: Option<&'static CFString>;
499}
500
501extern "C" {
502    /// [Apple's documentation](https://developer.apple.com/documentation/corefoundation/kcfsocketregistercommand?language=objc)
503    #[cfg(feature = "CFBase")]
504    pub static kCFSocketRegisterCommand: Option<&'static CFString>;
505}
506
507extern "C" {
508    /// [Apple's documentation](https://developer.apple.com/documentation/corefoundation/kcfsocketretrievecommand?language=objc)
509    #[cfg(feature = "CFBase")]
510    pub static kCFSocketRetrieveCommand: Option<&'static CFString>;
511}