Hello,
I've been working with the Cocoa bindings and I came across a bug
today. When writing a chunk of data greater than a certain size (in my
case a couple hundred kilobytes), NSOutputStream can't write the data
in one chunk. The existing code detects this and throws an exception,
so it is impossible to send a struct greater than a certain size. I've
fixed this limitation in the Obj-c code so that it loops until all of
the data has been sent.
I didn't see anything on how to contribute, and what the policy is, so
I've included the diff in this e-mail. How should I proceed?
Index: TNSStreamTransport.m
===================================================================
--- TNSStreamTransport.m (revision 790427)
+++ TNSStreamTransport.m (working copy)
@@ -65,17 +65,26 @@
}
-// FIXME:geech:20071019 - make this write all
- (void) write: (uint8_t *) data offset: (unsigned int) offset
length: (unsigned int) length
{
- int result = [mOutput write: data+offset maxLength: length];
- if (result == -1) {
- @throw [TTransportException exceptionWithReason: @"Error writing
to transport output stream."
- error: [mOutput
streamError]];
- } else if (result == 0) {
- @throw [TTransportException exceptionWithReason: @"End of output
stream."];
- } else if (result != length) {
- @throw [TTransportException exceptionWithReason: @"Output stream
did not write all of our data."];
+ int result = 0;
+ // Loops until all the data is sent
+ while (1) {
+ result = [mOutput write: data+offset maxLength: length];
+ if (result == -1) {
+ @throw [TTransportException exceptionWithReason: @"Error
writing to transport output stream."
+ error: [mOutput
streamError]];
+ } else if (result == 0) {
+ @throw [TTransportException exceptionWithReason: @"End of
output stream."];
+ }
+ if (result == length) {
+ break;
+ } else {
+ // result < length so not all the data was sent.
+ // slide the offset along and send more data
+ offset += result;
+ length -= result;
+ }
}
}
--
Matt Ronge
[email protected]
http://www.mronge.com