-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathNSStream+BoundPair.m
42 lines (33 loc) · 1.16 KB
/
NSStream+BoundPair.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
//
// NSStream+BoundPair.h
//
// Modified by Wes Smith: 8-24-12
//
// Extracted From: SimpleURLConnections sample project WWDC 2012
// Written by: DTS
// Copyright: Copyright (c) 2009-2012 Apple Inc. All Rights Reserved.
//
#import "NSStream+BoundPair.h"
#include <CFNetwork/CFNetwork.h>
@implementation NSStream (BoundPair)
+ (void)createBoundInputStream:(NSInputStream **)inputStreamPtr outputStream:(NSOutputStream **)outputStreamPtr bufferSize:(NSUInteger)bufferSize
{
CFReadStreamRef readStream;
CFWriteStreamRef writeStream;
assert( (inputStreamPtr != NULL) || (outputStreamPtr != NULL) );
readStream = NULL;
writeStream = NULL;
CFStreamCreateBoundPair(
NULL,
((inputStreamPtr != nil) ? &readStream : NULL),
((outputStreamPtr != nil) ? &writeStream : NULL),
(CFIndex) bufferSize
);
if (inputStreamPtr != NULL) {
*inputStreamPtr = CFBridgingRelease(readStream);
}
if (outputStreamPtr != NULL) {
*outputStreamPtr = CFBridgingRelease(writeStream);
}
}
@end