1 /* Copyright (c) 2008-2009 Christopher J. W. Lloyd
3 Permission is hereby granted,free of charge,to any person obtaining a copy of this software and associated documentation files (the "Software"),to deal in the Software without restriction,including without limitation the rights to use,copy,modify,merge,publish,distribute,sublicense,and/or sell copies of the Software,and to permit persons to whom the Software is furnished to do so,subject to the following conditions:
5 The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
7 THE SOFTWARE IS PROVIDED "AS IS",WITHOUT WARRANTY OF ANY KIND,EXPRESS OR IMPLIED,INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,DAMAGES OR OTHER LIABILITY,WHETHER IN AN ACTION OF CONTRACT,TORT OR OTHERWISE,ARISING FROM,OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
8 #import <CoreFoundation/CFBase.h>
9 #import <CoreFoundation/CFDate.h>
10 #import <CoreFoundation/CFRunLoop.h>
12 typedef struct __NSSocket
*CFSocketRef
;
15 CFInteger protocolFamily
;
22 kCFSocketNoCallBack
= 0,
23 kCFSocketReadCallBack
= 1,
24 kCFSocketAcceptCallBack
= 2,
25 kCFSocketDataCallBack
= 3,
26 kCFSocketConnectCallBack
= 4,
27 kCFSocketWriteCallBack
= 8,
28 } CFSocketCallBackType
;
31 kCFSocketAutomaticallyReenableReadCallBack
= 1,
32 kCFSocketAutomaticallyReenableAcceptCallBack
= 2,
33 kCFSocketAutomaticallyReenableDataCallBack
= 3,
34 kCFSocketAutomaticallyReenableWriteCallBack
= 8,
35 kCFSocketCloseOnInvalidate
= 128,
41 kCFSocketTimeout
= -2,
44 typedef void (*CFSocketCallBack
)(CFSocketRef self
, CFSocketCallBackType callbackType
, CFDataRef address
, const void *data
, void *info
);
49 CFAllocatorRetainCallBack retain
;
50 CFAllocatorReleaseCallBack release
;
51 CFAllocatorCopyDescriptionCallBack copyDescription
;
54 typedef int CFSocketNativeHandle
;
56 COREFOUNDATION_EXPORT CFTypeID
CFSocketGetTypeID();
58 COREFOUNDATION_EXPORT CFSocketRef
CFSocketCreate(CFAllocatorRef allocator
, CFInteger protocolFamily
, CFInteger socketType
, CFInteger protocol
, CFOptionFlags flags
, CFSocketCallBack callback
, const CFSocketContext
*context
);
59 COREFOUNDATION_EXPORT CFSocketRef
CFSocketCreateConnectedToSocketSignature(CFAllocatorRef allocator
, const CFSocketSignature
*signature
, CFOptionFlags flags
, CFSocketCallBack callback
, const CFSocketContext
*context
, CFTimeInterval timeout
);
61 COREFOUNDATION_EXPORT CFSocketRef
CFSocketCreateWithNative(CFAllocatorRef allocator
, CFSocketNativeHandle native
, CFOptionFlags flags
, CFSocketCallBack callback
, const CFSocketContext
*context
);
62 COREFOUNDATION_EXPORT CFSocketRef
CFSocketCreateWithSocketSignature(CFAllocatorRef allocator
, const CFSocketSignature
*signature
, CFOptionFlags flags
, CFSocketCallBack callback
, const CFSocketContext
*context
);
64 COREFOUNDATION_EXPORT CFSocketError
CFSocketConnectToAddress(CFSocketRef self
, CFDataRef address
, CFTimeInterval timeout
);
65 COREFOUNDATION_EXPORT CFDataRef
CFSocketCopyAddress(CFSocketRef self
);
66 COREFOUNDATION_EXPORT CFDataRef
CFSocketCopyPeerAddress(CFSocketRef self
);
67 COREFOUNDATION_EXPORT CFRunLoopSourceRef
CFSocketCreateRunLoopSource(CFAllocatorRef allocator
, CFSocketRef self
, CFIndex order
);
68 COREFOUNDATION_EXPORT
void CFSocketDisableCallBacks(CFSocketRef self
, CFOptionFlags flags
);
69 COREFOUNDATION_EXPORT
void CFSocketEnableCallBacks(CFSocketRef self
, CFOptionFlags flags
);
70 COREFOUNDATION_EXPORT
void CFSocketGetContext(CFSocketRef self
, CFSocketContext
*context
);
71 COREFOUNDATION_EXPORT CFSocketNativeHandle
CFSocketGetNative(CFSocketRef self
);
72 COREFOUNDATION_EXPORT CFOptionFlags
CFSocketGetSocketFlags(CFSocketRef self
);
74 COREFOUNDATION_EXPORT
void CFSocketInvalidate(CFSocketRef self
);
75 COREFOUNDATION_EXPORT Boolean
CFSocketIsValid(CFSocketRef self
);
76 COREFOUNDATION_EXPORT CFSocketError
CFSocketSendData(CFSocketRef self
, CFDataRef address
, CFDataRef data
, CFTimeInterval timeout
);
77 COREFOUNDATION_EXPORT CFSocketError
CFSocketSetAddress(CFSocketRef self
, CFDataRef address
);
78 COREFOUNDATION_EXPORT
void CFSocketSetSocketFlags(CFSocketRef self
, CFOptionFlags flags
);