GNUstep CoreBase Library 0.2
CFSocket.h
1/* CFSocket.h
2
3 Copyright (C) 2012 Free Software Foundation, Inc.
4
5 Author: Stefan Bidigaray <stefanbidi@gmail.com>
6 Date: September, 2012
7
8 This file is part of the GNUstep CoreBase Library.
9
10 This library is free software; you can redistribute it and/or
11 modify it under the terms of the GNU Lesser General Public
12 License as published by the Free Software Foundation; either
13 version 2.1 of the License, or (at your option) any later version.
14
15 This library is distributed in the hope that it will be useful,
16 but WITHOUT ANY WARRANTY; without even the implied warranty of
17 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
18 Lesser General Public License for more details.
19
20 You should have received a copy of the GNU Lesser General Public
21 License along with this library; see the file COPYING.LIB.
22 If not, see <http://www.gnu.org/licenses/> or write to the
23 Free Software Foundation, 51 Franklin Street, Fifth Floor,
24 Boston, MA 02110-1301, USA.
25*/
26
27#ifndef __COREFOUNDATION_CFSOCKET_H__
28#define __COREFOUNDATION_CFSOCKET_H__
29
30#include <CoreFoundation/CFBase.h>
31#include <CoreFoundation/CFData.h>
32#include <CoreFoundation/CFDate.h>
33
34CF_EXTERN_C_BEGIN
38typedef struct __CFSocket *CFSocketRef;
39
40#if defined(_WIN32)
41#include <winsock2.h>
42typedef SOCKET CFSocketNativeHandle;
43#else
44typedef int CFSocketNativeHandle;
45#endif
46
47typedef struct CFSocketContext CFSocketContext;
49{
50 CFIndex version;
51 void *info;
52 CFAllocatorRetainCallBack retain;
53 CFAllocatorReleaseCallBack release;
54 CFAllocatorCopyDescriptionCallBack copyDescription;
55};
56
59{
60 SInt32 protocolFamily;
61 SInt32 socketType;
62 SInt32 protocol;
63 CFDataRef address;
64};
65
66typedef enum
67{
68 kCFSocketNoCallBack = 0,
69 kCFSocketReadCallBack = 1,
70 kCFSocketAcceptCallBack = 2,
71 kCFSocketDataCallBack = 3,
72 kCFSocketConnectCallBack = 4
73#if OS_API_VERSION(MAC_OS_X_VERSION_10_2, GS_API_LATEST)
74 ,
75 kCFSocketWriteCallBack = 8
76#endif
77} CFSocketCallBackType;
78
79#if OS_API_VERSION(MAC_OS_X_VERSION_10_2, GS_API_LATEST)
80enum
81{
82 kCFSocketAutomaticallyReenableReadCallBack = 1,
83 kCFSocketAutomaticallyReenableAcceptCallBack = 2,
84 kCFSocketAutomaticallyReenableDataCallBack = 3,
85 kCFSocketAutomaticallyReenableWriteCallBack = 8,
86#if OS_API_VERSION(MAC_OS_X_VERSION_10_6, GS_API_LATEST)
87 kCFSocketLeaveErrors = 64,
88#endif
89 kCFSocketCloseOnInvalidate = 128
90};
91#endif
92
93typedef enum
94{
95 kCFSocketSuccess = 0,
96 kCFSocketError = -1,
97 kCFSocketTimeout = -2
98} CFSocketError;
99
100typedef void (*CFSocketCallBack) (CFSocketRef s,
101 CFSocketCallBackType callbackType,
102 CFDataRef address,
103 const void *data, void *info);
109CF_EXPORT const CFStringRef kCFSocketCommandKey;
110CF_EXPORT const CFStringRef kCFSocketNameKey;
111CF_EXPORT const CFStringRef kCFSocketValueKey;
112CF_EXPORT const CFStringRef kCFSocketResultKey;
113CF_EXPORT const CFStringRef kCFSocketErrorKey;
114CF_EXPORT const CFStringRef kCFSocketRegisterCommand;
115CF_EXPORT const CFStringRef kCFSocketRetrieveCommand;
118CF_EXPORT CFTypeID CFSocketGetTypeID (void);
119
126CF_EXPORT CFSocketRef
127CFSocketCreate (CFAllocatorRef allocator, SInt32 protocolFamily,
128 SInt32 socketType, SInt32 protocol,
129 CFOptionFlags callBackTypes, CFSocketCallBack callout,
130 const CFSocketContext * context);
131
132CF_EXPORT CFSocketRef
133CFSocketCreateConnectedToSocketSignature (CFAllocatorRef allocator,
134 const CFSocketSignature * signature,
135 CFOptionFlags callBackTypes,
136 CFSocketCallBack callout,
137 const CFSocketContext * context,
138 CFTimeInterval timeout);
139
140CF_EXPORT CFSocketRef
141CFSocketCreateWithNative (CFAllocatorRef allocator, CFSocketNativeHandle sock,
142 CFOptionFlags callBackTypes,
143 CFSocketCallBack callout,
144 const CFSocketContext * context);
145
146CF_EXPORT CFSocketRef
147CFSocketCreateWithSocketSignature (CFAllocatorRef allocator,
148 const CFSocketSignature * signature,
149 CFOptionFlags callBackTypes,
150 CFSocketCallBack callout,
151 const CFSocketContext * context);
157CF_EXPORT CFDataRef CFSocketCopyAddress (CFSocketRef s);
158
159CF_EXPORT CFDataRef CFSocketCopyPeerAddress (CFSocketRef s);
160
161CF_EXPORT void CFSocketGetContext (CFSocketRef s, CFSocketContext * context);
162
163CF_EXPORT CFSocketNativeHandle CFSocketGetNative (CFSocketRef s);
164
165CF_EXPORT CFSocketError CFSocketSetAddress (CFSocketRef s, CFDataRef address);
166
167#if OS_API_VERSION(MAC_OS_X_VERSION_10_2, GS_API_LATEST)
168CF_EXPORT void
169CFSocketDisableCallBacks (CFSocketRef s, CFOptionFlags callBackTypes);
170
171CF_EXPORT void
172CFSocketEnableCallBacks (CFSocketRef s, CFOptionFlags callBackTypes);
173
174CF_EXPORT CFOptionFlags CFSocketGetSocketFlags (CFSocketRef s);
175
176CF_EXPORT void CFSocketSetSocketFlags (CFSocketRef s, CFOptionFlags flags);
177#endif
183CF_EXPORT CFSocketError
184CFSocketConnectToAddress (CFSocketRef s, CFDataRef address,
185 CFTimeInterval timeout);
186
187CF_EXPORT CFRunLoopSourceRef
188CFSocketCreateRunLoopSource (CFAllocatorRef allocator, CFSocketRef s,
189 CFIndex order);
190
191CF_EXPORT void CFSocketInvalidate (CFSocketRef s);
192
193CF_EXPORT Boolean CFSocketIsValid (CFSocketRef s);
194
195CF_EXPORT CFSocketError
196CFSocketSendData (CFSocketRef s, CFDataRef address, CFDataRef data,
197 CFTimeInterval timeout);
204CF_EXPORT CFSocketError
205CFSocketCopyRegisteredSocketSignature (const CFSocketSignature *
206 nameServerSignature,
207 CFTimeInterval timeout, CFStringRef name,
208 CFSocketSignature * signature,
209 CFDataRef * nameServerAddress);
210
211CF_EXPORT CFSocketError
212CFSocketCopyRegisteredValue (const CFSocketSignature * nameServerSignature,
213 CFTimeInterval timeout,
214 CFStringRef name,
215 CFPropertyListRef * value,
216 CFDataRef * nameServerAddress);
217
218CF_EXPORT UInt16 CFSocketGetDefaultNameRegistryPortNumber (void);
219
220CF_EXPORT CFSocketError
221CFSocketRegisterSocketSignature (const CFSocketSignature * nameServerSignature,
222 CFTimeInterval timeout,
223 CFStringRef name,
224 const CFSocketSignature * signature);
225
226CF_EXPORT CFSocketError
227CFSocketRegisterValue (const CFSocketSignature * nameServerSignature,
228 CFTimeInterval timeout,
229 CFStringRef name, CFPropertyListRef value);
230
231CF_EXPORT void CFSocketSetDefaultNameRegistryPortNumber (UInt16 port);
232
233CF_EXPORT CFSocketError
234CFSocketUnregister (const CFSocketSignature * nameServerSignature,
235 CFTimeInterval timeout, CFStringRef name);
238CF_EXTERN_C_END
239#endif /* __COREFOUNDATION_CFSOCKET_H__ */
unsigned long CFOptionFlags
Definition CFBase.h:163
signed long CFIndex
Definition CFBase.h:165
const struct __CFAllocator * CFAllocatorRef
A reference to a CFAllocator object.
Definition CFBase.h:301
Definition CFSocket.h:49
Definition CFSocket.h:59