Re: Reading from an NSInputStream
Re: Reading from an NSInputStream
- Subject: Re: Reading from an NSInputStream
- From: Troy Dawson <email@hidden>
- Date: Sat, 22 Nov 2003 09:03:03 -0800
>
uint8_t *buf;
>
unsigned int *numBytes;
>
[stream getBuffer:&buf length:numBytes];
>
for (int i = 0; i < *numBytes; i++) {
>
printf("%c", buf[i]);
>
}
>
}
>
}
>
>
Once the code hits here, however, the application receives signal 11
>
underneath the [inputStream getBuffer:&buf length:numBytes] call, in
>
Apple's code.
>
>
I imagine I'm doing something drastically wrong here, but I can't for
>
the life of me figure out what it is. Any help would be greatly
>
appreciated.
I think you want the -read method:
// reads up to length bytes into the supplied buffer, which must be at
least of size len. Returns the actual number of bytes read.
the -getBuffer method has the following comment:
// returns in O(1) a pointer to the buffer in 'buffer' and by
reference in 'len' how many bytes are available. This buffer is only
valid until the next stream operation. Subclassers may return NO for
this if it is not appropriate for the stream type. This may return NO
if the buffer is not available.
you're not checking the return of getBuffer, which can and will return
NO if it doesn't like you.
_______________________________________________
cocoa-dev mailing list | email@hidden
Help/Unsubscribe/Archives:
http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.