From 03f4659640e18499434614493563795c2d3819d3 Mon Sep 17 00:00:00 2001 From: Robert Sesek Date: Wed, 4 Jun 2008 15:18:52 -0400 Subject: [PATCH] Instead of using NSData for [SocketWrapper receive], use NSString * Source/DebuggerConnection.m: ([processData:]): Use NSString instead of NSData * Source/SocketWrapper.m+h: ([receive]): Return an NSString --- Source/DebuggerConnection.m | 8 ++++---- Source/SocketWrapper.h | 2 +- Source/SocketWrapper.m | 11 ++++++----- 3 files changed, 11 insertions(+), 10 deletions(-) diff --git a/Source/DebuggerConnection.m b/Source/DebuggerConnection.m index fc75d53..10b3c47 100644 --- a/Source/DebuggerConnection.m +++ b/Source/DebuggerConnection.m @@ -20,7 +20,7 @@ @interface DebuggerConnection (Private) - (NSString *)createCommand:(NSString *)cmd; -- (NSXMLDocument *)processData:(NSData *)data; +- (NSXMLDocument *)processData:(NSString *)data; @end @@ -269,15 +269,15 @@ /** * Helper function to parse the NSData into an NSXMLDocument */ -- (NSXMLDocument *)processData:(NSData *)data +- (NSXMLDocument *)processData:(NSString *)data { NSError *parseError = nil; - NSXMLDocument *doc = [[NSXMLDocument alloc] initWithData:data options:NSXMLDocumentTidyXML error:&parseError]; + NSXMLDocument *doc = [[NSXMLDocument alloc] initWithXMLString:data options:0 error:&parseError]; if (parseError) { NSLog(@"Could not parse XML? --- %@", parseError); NSLog(@"Error UserInfo: %@", [parseError userInfo]); - NSLog(@"This is the XML Document: %@", [[NSString alloc] initWithData:data encoding:NSUTF8StringEncoding]); + NSLog(@"This is the XML Document: %@", data); return nil; } diff --git a/Source/SocketWrapper.h b/Source/SocketWrapper.h index ee170af..1501393 100644 --- a/Source/SocketWrapper.h +++ b/Source/SocketWrapper.h @@ -35,7 +35,7 @@ - (void)connect; - (void)close; -- (NSData *)receive; +- (NSString *)receive; - (BOOL)send:(NSString *)data; - (NSString *)remoteHost; diff --git a/Source/SocketWrapper.m b/Source/SocketWrapper.m index 77e8cda..8d6e094 100644 --- a/Source/SocketWrapper.m +++ b/Source/SocketWrapper.m @@ -156,7 +156,7 @@ * is used either in a threaded environment so the interface does not hang, or when you *know* the server * will return something (which we almost always do). Returns the data that was received from the socket. */ -- (NSData *)receive +- (NSString *)receive { // create a buffer char buffer[1024]; @@ -166,6 +166,7 @@ // take the received data and put it into an NSData NSMutableData *data = [NSMutableData data]; + NSMutableString *str = [NSMutableString string]; // strip the length from the packet, and clear the null byte then add it to the NSData char packetLength[8]; @@ -188,8 +189,8 @@ memset(packet, '\0', sizeof(packet)); memmove(packet, &buffer[i], recvd - i); - // convert bytes to NSData - [data appendBytes:packet length:recvd - i]; + // convert bytes to NSString + [str appendString:[[NSString alloc] initWithCString:packet length:recvd - i]]; // check if we have a partial packet if (length + i > sizeof(buffer)) @@ -202,12 +203,12 @@ [self error:@"Socket closed or could not be read"]; return nil; } - [data appendBytes:buffer length:latest]; + [str appendString:[[NSString alloc] initWithCString:buffer length:latest]]; recvd += latest; } } - return data; + return [str stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceAndNewlineCharacterSet]]; } /** -- 2.43.5