THRIFT-549. Make socket client compatible with iPhone SDK as well as OS X

git-svn-id: https://svn.apache.org/repos/asf/incubator/thrift/trunk@797545 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Andrew McGeachie 2009-07-24 15:58:07 +00:00
parent 061722b4fd
commit bbd55ad8da

View File

@ -16,28 +16,39 @@
* specific language governing permissions and limitations
* under the License.
*/
#import <Foundation/Foundation.h>
#import "TSocketClient.h"
#import <CFNetwork/CFSocketStream.h>
@implementation TSocketClient
- (id) initWithHostname: (NSString *) hostname
port: (int) port
{
NSInputStream * input = nil;
NSOutputStream * output = nil;
[NSStream getStreamsToHost: [NSHost hostWithName: hostname]
port: port
inputStream: &input
outputStream: &output];
self = [super initWithInputStream: input outputStream: output];
[input open];
[output open];
return self;
NSInputStream * inputStream = NULL;
NSOutputStream * outputStream = NULL;
CFReadStreamRef readStream = NULL;
CFWriteStreamRef writeStream = NULL;
CFStreamCreatePairWithSocketToHost(kCFAllocatorDefault, (CFStringRef)hostname, port, &readStream, &writeStream);
if (readStream && writeStream) {
CFReadStreamSetProperty(readStream, kCFStreamPropertyShouldCloseNativeSocket, kCFBooleanTrue);
CFWriteStreamSetProperty(writeStream, kCFStreamPropertyShouldCloseNativeSocket, kCFBooleanTrue);
inputStream = (NSInputStream *)readStream;
[inputStream retain];
[inputStream setDelegate:self];
[inputStream scheduleInRunLoop:[NSRunLoop currentRunLoop] forMode:NSDefaultRunLoopMode];
[inputStream open];
outputStream = (NSOutputStream *)writeStream;
[outputStream retain];
[outputStream setDelegate:self];
[outputStream scheduleInRunLoop:[NSRunLoop currentRunLoop] forMode:NSDefaultRunLoopMode];
[outputStream open];
}
self = [super initWithInputStream: inputStream outputStream: outputStream];
return self;
}