FROM : Development
DATE : Sun Jan 13 23:41:02 2008
Below is a snippet of the code I'm using for getting the incoming data
from the stream. It is cutting download speed from what it should be
at around 200Kbps to 22 - 30 Kbps.. I know it is because it reads the
data one byte at a time but my attempts to have it read all bytes
available have produced much failure. Can any one suggest how to speed
this piece of code up? (The main problem I've been having is that if
it reads the whole buffer I cannot seem to find the \r\n any where,
and so the program cannot find the end of the message from the server.
Also when I tre the getBuffer:length: function, the length I get seems
always to be 0.
- (void)stream:(NSStream *)aStream handleEvent:
(NSStreamEvent)streamEvent {
NSInputStream * instream;
NSString * error;
switch(streamEvent) {
case NSStreamEventHasBytesAvailable:;
uint8_t oneByte;
int actuallyRead = 0;
instream = (NSInputStream *)aStream;
if (!dataBuffer) {
dataBuffer = [[NSMutableData alloc] initWithCapacity:
2048];
}
actuallyRead = [istream read:&oneByte maxLength:1]; <- if
I set max length to 2048 it crashes
if (actuallyRead == 1) {
[dataBuffer appendBytes:&oneByte length:1];
}
if (oneByte == '\n' || oneByte == '\r') {
[self newBytesAvailable:dataBuffer];
[dataBuffer release];
dataBuffer = nil;
}
break;
DATE : Sun Jan 13 23:41:02 2008
Below is a snippet of the code I'm using for getting the incoming data
from the stream. It is cutting download speed from what it should be
at around 200Kbps to 22 - 30 Kbps.. I know it is because it reads the
data one byte at a time but my attempts to have it read all bytes
available have produced much failure. Can any one suggest how to speed
this piece of code up? (The main problem I've been having is that if
it reads the whole buffer I cannot seem to find the \r\n any where,
and so the program cannot find the end of the message from the server.
Also when I tre the getBuffer:length: function, the length I get seems
always to be 0.
- (void)stream:(NSStream *)aStream handleEvent:
(NSStreamEvent)streamEvent {
NSInputStream * instream;
NSString * error;
switch(streamEvent) {
case NSStreamEventHasBytesAvailable:;
uint8_t oneByte;
int actuallyRead = 0;
instream = (NSInputStream *)aStream;
if (!dataBuffer) {
dataBuffer = [[NSMutableData alloc] initWithCapacity:
2048];
}
actuallyRead = [istream read:&oneByte maxLength:1]; <- if
I set max length to 2048 it crashes
if (actuallyRead == 1) {
[dataBuffer appendBytes:&oneByte length:1];
}
if (oneByte == '\n' || oneByte == '\r') {
[self newBytesAvailable:dataBuffer];
[dataBuffer release];
dataBuffer = nil;
}
break;
| Related mails | Author | Date |
|---|---|---|
| Development | Jan 13, 00:24 | |
| Development | Jan 13, 02:16 | |
| Andrew Farmer | Jan 13, 02:36 | |
| Brady Duga | Jan 13, 02:51 | |
| Keary Suska | Jan 13, 18:15 | |
| Development | Jan 13, 20:19 | |
| Development | Jan 13, 23:41 | |
| Andrew Farmer | Jan 14, 00:12 | |
| Ryan Homer | Jan 14, 14:28 |






Cocoa mail archive

