]> git.saurik.com Git - apple/cf.git/blob - CFStreamPriv.h
CF-550.13.tar.gz
[apple/cf.git] / CFStreamPriv.h
1 /*
2 * Copyright (c) 2009 Apple Inc. All rights reserved.
3 *
4 * @APPLE_LICENSE_HEADER_START@
5 *
6 * This file contains Original Code and/or Modifications of Original Code
7 * as defined in and that are subject to the Apple Public Source License
8 * Version 2.0 (the 'License'). You may not use this file except in
9 * compliance with the License. Please obtain a copy of the License at
10 * http://www.opensource.apple.com/apsl/ and read it before using this
11 * file.
12 *
13 * The Original Code and all software distributed under the License are
14 * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
15 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
16 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
17 * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
18 * Please see the License for the specific language governing rights and
19 * limitations under the License.
20 *
21 * @APPLE_LICENSE_HEADER_END@
22 */
23
24 /* CFStreamPriv.h
25 Copyright (c) 2000-2009, Apple Inc. All rights reserved.
26 */
27
28 #if !defined(__COREFOUNDATION_CFSTREAMPRIV__)
29 #define __COREFOUNDATION_CFSTREAMPRIV__ 1
30
31 #include <CoreFoundation/CFStream.h>
32 #include <CoreFoundation/CFRunLoop.h>
33 #include <CoreFoundation/CFRuntime.h>
34
35 CF_EXTERN_C_BEGIN
36
37 struct _CFStream;
38 struct _CFStreamClient {
39 CFStreamClientContext cbContext;
40 void (*cb)(struct _CFStream *, CFStreamEventType, void *);
41 CFOptionFlags when;
42 CFRunLoopSourceRef rlSource;
43 CFMutableArrayRef runLoopsAndModes;
44 CFOptionFlags whatToSignal;
45 };
46
47 #define CFStreamCurrentVersion 2
48
49 // A unified set of callbacks so we can use a single structure for all struct _CFStreams.
50 struct _CFStreamCallBacks {
51 CFIndex version;
52 void *(*create)(struct _CFStream *stream, void *info);
53 void (*finalize)(struct _CFStream *stream, void *info);
54 CFStringRef (*copyDescription)(struct _CFStream *stream, void *info);
55
56 Boolean (*open)(struct _CFStream *stream, CFErrorRef *error, Boolean *openComplete, void *info);
57 Boolean (*openCompleted)(struct _CFStream *stream, CFErrorRef *error, void *info);
58 CFIndex (*read)(CFReadStreamRef stream, UInt8 *buffer, CFIndex bufferLength, CFErrorRef *error, Boolean *atEOF, void *info);
59 const UInt8 *(*getBuffer)(CFReadStreamRef sream, CFIndex maxBytesToRead, CFIndex *numBytesRead, CFErrorRef *error, Boolean *atEOF, void *info);
60 Boolean (*canRead)(CFReadStreamRef, CFErrorRef *error, void *info);
61 CFIndex (*write)(CFWriteStreamRef, const UInt8 *buffer, CFIndex bufferLength, CFErrorRef *error, void *info);
62 Boolean (*canWrite)(CFWriteStreamRef, CFErrorRef *error, void *info);
63 void (*close)(struct _CFStream *stream, void *info);
64
65 CFTypeRef (*copyProperty)(struct _CFStream *stream, CFStringRef propertyName, void *info);
66 Boolean (*setProperty)(struct _CFStream *stream, CFStringRef propertyName, CFTypeRef propertyValue, void *info);
67 void (*requestEvents)(struct _CFStream *stream, CFOptionFlags events, void *info);
68 void (*schedule)(struct _CFStream *stream, CFRunLoopRef runLoop, CFStringRef runLoopMode, void *info);
69 void (*unschedule)(struct _CFStream *stream, CFRunLoopRef runLoop, CFStringRef runLoopMode, void *info);
70 };
71
72 struct _CFStream {
73 CFRuntimeBase _cfBase;
74 CFOptionFlags flags;
75 CFErrorRef error; // if callBacks->version < 2, this is actually a pointer to a CFStreamError
76 struct _CFStreamClient *client;
77 void *info;
78 const struct _CFStreamCallBacks *callBacks; // This will not exist (will not be allocated) if the callbacks are from our known, "blessed" set.
79 void *_reserved1;
80 };
81
82
83 CF_INLINE void *_CFStreamGetInfoPointer(struct _CFStream *stream) {
84 return stream->info;
85 }
86
87
88 // cb version must be > 0
89 CF_EXPORT struct _CFStream *_CFStreamCreateWithConstantCallbacks(CFAllocatorRef alloc, void *info, const struct _CFStreamCallBacks *cb, Boolean isReading);
90
91 // Only available for streams created with _CFStreamCreateWithConstantCallbacks, above. cb's version must be 1
92 CF_EXPORT void _CFStreamSetInfoPointer(struct _CFStream *stream, void *info, const struct _CFStreamCallBacks *cb);
93
94 /*
95 ** _CFStreamSourceScheduleWithRunLoop
96 **
97 ** Schedules the given run loop source on the given run loop and mode. It then
98 ** adds the loop and mode pair to the runLoopsAndModes list. The list is
99 ** simply a linear list of a loop reference followed by a mode reference.
100 **
101 ** source Run loop source to be scheduled
102 **
103 ** runLoopsAndModes List of run loop/mode pairs on which the source is scheduled
104 **
105 ** runLoop Run loop on which the source is being scheduled
106 **
107 ** runLoopMode Run loop mode on which the source is being scheduled
108 */
109 CF_EXPORT
110 void _CFStreamSourceScheduleWithRunLoop(CFRunLoopSourceRef source, CFMutableArrayRef runLoopsAndModes, CFRunLoopRef runLoop, CFStringRef runLoopMode);
111
112
113 /*
114 ** _CFStreamSourceUnscheduleFromRunLoop
115 **
116 ** Unschedule the given source from the given run loop and mode. It then will
117 ** guarantee that the source remains scheduled on the list of run loop and mode
118 ** pairs in the runLoopsAndModes list. The list is simply a linear list of a
119 ** loop reference followed by a mode reference.
120 **
121 ** source Run loop source to be unscheduled
122 **
123 ** runLoopsAndModes List of run loop/mode pairs on which the source is scheduled
124 **
125 ** runLoop Run loop from which the source is being unscheduled
126 **
127 ** runLoopMode Run loop mode from which the source is being unscheduled
128 */
129 CF_EXPORT
130 void _CFStreamSourceUnscheduleFromRunLoop(CFRunLoopSourceRef source, CFMutableArrayRef runLoopsAndModes, CFRunLoopRef runLoop, CFStringRef runLoopMode);
131
132
133 /*
134 ** _CFStreamSourceScheduleWithAllRunLoops
135 **
136 ** Schedules the given run loop source on all the run loops and modes in the list.
137 ** The list is simply a linear list of a loop reference followed by a mode reference.
138 **
139 ** source Run loop source to be unscheduled
140 **
141 ** runLoopsAndModes List of run loop/mode pairs on which the source is scheduled
142 */
143 CF_EXPORT
144 void _CFStreamSourceScheduleWithAllRunLoops(CFRunLoopSourceRef source, CFArrayRef runLoopsAndModes);
145
146
147 /*
148 ** _CFStreamSourceUnscheduleFromRunLoop
149 **
150 ** Unschedule the given source from all the run loops and modes in the list.
151 ** The list is simply a linear list of a loop reference followed by a mode
152 ** reference.
153 **
154 ** source Run loop source to be unscheduled
155 **
156 ** runLoopsAndModes List of run loop/mode pairs on which the source is scheduled
157 */
158 CF_EXPORT
159 void _CFStreamSourceUncheduleFromAllRunLoops(CFRunLoopSourceRef source, CFArrayRef runLoopsAndModes);
160
161 CF_EXPORT
162 CFReadStreamRef _CFReadStreamCreateFromFileDescriptor(CFAllocatorRef alloc, int fd);
163
164 CF_EXPORT
165 CFWriteStreamRef _CFWriteStreamCreateFromFileDescriptor(CFAllocatorRef alloc, int fd);
166
167
168
169 #define SECURITY_NONE (0)
170 #define SECURITY_SSLv2 (1)
171 #define SECURITY_SSLv3 (2)
172 #define SECURITY_SSLv32 (3)
173 #define SECURITY_TLS (4)
174
175 #if (TARGET_OS_MAC && !(TARGET_OS_EMBEDDED || TARGET_OS_IPHONE)) || (TARGET_OS_EMBEDDED || TARGET_OS_IPHONE)
176 // This symbol is exported from CFNetwork (see CFSocketStream.i). Only __MACH__ systems will
177 // get this symbol from CoreFoundation.
178 extern const int kCFStreamErrorDomainSSL;
179 #endif
180
181 /*
182 * Additional SPI for CFNetwork for select side read buffering
183 */
184 CF_EXPORT
185 Boolean __CFSocketGetBytesAvailable(CFSocketRef s, CFIndex* ctBytesAvailable);
186
187 CF_EXPORT
188 CFIndex __CFSocketRead(CFSocketRef s, UInt8* buffer, CFIndex length, int* error);
189
190 /*
191 * This define can be removed once 6030579 is removed
192 */
193 #define CFNETWORK_6030579 1
194
195 CF_EXPORT
196 void __CFSocketSetSocketReadBufferAttrs(CFSocketRef s, CFTimeInterval timeout, CFIndex length);
197
198 CF_EXTERN_C_END
199
200 #endif /* ! __COREFOUNDATION_CFSTREAMPRIV__ */
201