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