2 * Copyright (c) 2008 Apple Inc. All rights reserved.
4 * @APPLE_LICENSE_HEADER_START@
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
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.
21 * @APPLE_LICENSE_HEADER_END@
24 Copyright (c) 2000-2007, Apple Inc. All rights reserved.
27 #if !defined(__COREFOUNDATION_CFSTREAMPRIV__)
28 #define __COREFOUNDATION_CFSTREAMPRIV__ 1
30 #include <CoreFoundation/CFStream.h>
31 #include <CoreFoundation/CFRunLoop.h>
32 #include <CoreFoundation/CFRuntime.h>
37 struct _CFStreamClient
{
38 CFStreamClientContext cbContext
;
39 void (*cb
)(struct _CFStream
*, CFStreamEventType
, void *);
41 CFRunLoopSourceRef rlSource
;
42 CFMutableArrayRef runLoopsAndModes
;
43 CFOptionFlags whatToSignal
;
46 #define CFStreamCurrentVersion 2
48 // A unified set of callbacks so we can use a single structure for all struct _CFStreams.
49 struct _CFStreamCallBacks
{
51 void *(*create
)(struct _CFStream
*stream
, void *info
);
52 void (*finalize
)(struct _CFStream
*stream
, void *info
);
53 CFStringRef (*copyDescription
)(struct _CFStream
*stream
, void *info
);
55 Boolean (*open
)(struct _CFStream
*stream
, CFErrorRef
*error
, Boolean
*openComplete
, void *info
);
56 Boolean (*openCompleted
)(struct _CFStream
*stream
, CFErrorRef
*error
, void *info
);
57 CFIndex (*read
)(CFReadStreamRef stream
, UInt8
*buffer
, CFIndex bufferLength
, CFErrorRef
*error
, Boolean
*atEOF
, void *info
);
58 const UInt8
*(*getBuffer
)(CFReadStreamRef sream
, CFIndex maxBytesToRead
, CFIndex
*numBytesRead
, CFErrorRef
*error
, Boolean
*atEOF
, void *info
);
59 Boolean (*canRead
)(CFReadStreamRef
, CFErrorRef
*error
, void *info
);
60 CFIndex (*write
)(CFWriteStreamRef
, const UInt8
*buffer
, CFIndex bufferLength
, CFErrorRef
*error
, void *info
);
61 Boolean (*canWrite
)(CFWriteStreamRef
, CFErrorRef
*error
, void *info
);
62 void (*close
)(struct _CFStream
*stream
, void *info
);
64 CFTypeRef (*copyProperty
)(struct _CFStream
*stream
, CFStringRef propertyName
, void *info
);
65 Boolean (*setProperty
)(struct _CFStream
*stream
, CFStringRef propertyName
, CFTypeRef propertyValue
, void *info
);
66 void (*requestEvents
)(struct _CFStream
*stream
, CFOptionFlags events
, void *info
);
67 void (*schedule
)(struct _CFStream
*stream
, CFRunLoopRef runLoop
, CFStringRef runLoopMode
, void *info
);
68 void (*unschedule
)(struct _CFStream
*stream
, CFRunLoopRef runLoop
, CFStringRef runLoopMode
, void *info
);
72 CFRuntimeBase _cfBase
;
74 CFErrorRef error
; // if callBacks->version < 2, this is actually a pointer to a CFStreamError
75 struct _CFStreamClient
*client
;
77 const struct _CFStreamCallBacks
*callBacks
; // This will not exist (will not be allocated) if the callbacks are from our known, "blessed" set.
82 CF_INLINE
void *_CFStreamGetInfoPointer(struct _CFStream
*stream
) {
87 // cb version must be > 0
88 CF_EXPORT
struct _CFStream
*_CFStreamCreateWithConstantCallbacks(CFAllocatorRef alloc
, void *info
, const struct _CFStreamCallBacks
*cb
, Boolean isReading
);
90 // Only available for streams created with _CFStreamCreateWithConstantCallbacks, above. cb's version must be 1
91 CF_EXPORT
void _CFStreamSetInfoPointer(struct _CFStream
*stream
, void *info
, const struct _CFStreamCallBacks
*cb
);
94 ** _CFStreamSourceScheduleWithRunLoop
96 ** Schedules the given run loop source on the given run loop and mode. It then
97 ** adds the loop and mode pair to the runLoopsAndModes list. The list is
98 ** simply a linear list of a loop reference followed by a mode reference.
100 ** source Run loop source to be scheduled
102 ** runLoopsAndModes List of run loop/mode pairs on which the source is scheduled
104 ** runLoop Run loop on which the source is being scheduled
106 ** runLoopMode Run loop mode on which the source is being scheduled
109 void _CFStreamSourceScheduleWithRunLoop(CFRunLoopSourceRef source
, CFMutableArrayRef runLoopsAndModes
, CFRunLoopRef runLoop
, CFStringRef runLoopMode
);
113 ** _CFStreamSourceUnscheduleFromRunLoop
115 ** Unschedule the given source from the given run loop and mode. It then will
116 ** guarantee that the source remains scheduled on the list of run loop and mode
117 ** pairs in the runLoopsAndModes list. The list is simply a linear list of a
118 ** loop reference followed by a mode reference.
120 ** source Run loop source to be unscheduled
122 ** runLoopsAndModes List of run loop/mode pairs on which the source is scheduled
124 ** runLoop Run loop from which the source is being unscheduled
126 ** runLoopMode Run loop mode from which the source is being unscheduled
129 void _CFStreamSourceUnscheduleFromRunLoop(CFRunLoopSourceRef source
, CFMutableArrayRef runLoopsAndModes
, CFRunLoopRef runLoop
, CFStringRef runLoopMode
);
133 ** _CFStreamSourceScheduleWithAllRunLoops
135 ** Schedules the given run loop source on all the run loops and modes in the list.
136 ** The list is simply a linear list of a loop reference followed by a mode reference.
138 ** source Run loop source to be unscheduled
140 ** runLoopsAndModes List of run loop/mode pairs on which the source is scheduled
143 void _CFStreamSourceScheduleWithAllRunLoops(CFRunLoopSourceRef source
, CFArrayRef runLoopsAndModes
);
147 ** _CFStreamSourceUnscheduleFromRunLoop
149 ** Unschedule the given source from all the run loops and modes in the list.
150 ** The list is simply a linear list of a loop reference followed by a mode
153 ** source Run loop source to be unscheduled
155 ** runLoopsAndModes List of run loop/mode pairs on which the source is scheduled
158 void _CFStreamSourceUncheduleFromAllRunLoops(CFRunLoopSourceRef source
, CFArrayRef runLoopsAndModes
);
161 CFReadStreamRef
_CFReadStreamCreateFromFileDescriptor(CFAllocatorRef alloc
, int fd
);
164 CFWriteStreamRef
_CFWriteStreamCreateFromFileDescriptor(CFAllocatorRef alloc
, int fd
);
168 #define SECURITY_NONE (0)
169 #define SECURITY_SSLv2 (1)
170 #define SECURITY_SSLv3 (2)
171 #define SECURITY_SSLv32 (3)
172 #define SECURITY_TLS (4)
174 #if defined (__MACH__)
175 // This symbol is exported from CFNetwork (see CFSocketStream.i). Only __MACH__ systems will
176 // get this symbol from CoreFoundation.
177 extern const int kCFStreamErrorDomainSSL
;
181 * Additional SPI for CFNetwork for select side read buffering
184 Boolean
__CFSocketGetBytesAvailable(CFSocketRef s
, CFIndex
* ctBytesAvailable
);
187 CFIndex
__CFSocketRead(CFSocketRef s
, UInt8
* buffer
, CFIndex length
, int* error
);
190 void __CFSocketSetReadBufferLength(CFSocketRef s
, CFIndex length
);
193 void __CFSocketSetReadBufferTimeout(CFSocketRef s
, CFTimeInterval timeout
);
197 #endif /* ! __COREFOUNDATION_CFSTREAMPRIV__ */