From: Andrew McGeachie Date: Tue, 21 Jul 2009 15:34:07 +0000 (+0000) Subject: THRIFT-533. Fix write:offset:length: to ensure all requested data is written. X-Git-Tag: 0.2.0~68 X-Git-Url: https://source.supwisdom.com/gerrit/gitweb?a=commitdiff_plain;h=59ace01f3f15e2babc952cafa86310abdd29b114;p=common%2Fthrift.git THRIFT-533. Fix write:offset:length: to ensure all requested data is written. git-svn-id: https://svn.apache.org/repos/asf/incubator/thrift/trunk@796351 13f79535-47bb-0310-9956-ffa450edef68 --- diff --git a/lib/cocoa/src/transport/TNSStreamTransport.m b/lib/cocoa/src/transport/TNSStreamTransport.m index 52a02e27..1d4cfeec 100644 --- a/lib/cocoa/src/transport/TNSStreamTransport.m +++ b/lib/cocoa/src/transport/TNSStreamTransport.m @@ -65,17 +65,19 @@ } -// 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 got = 0; + int result = 0; + while (got < length) { + result = [mOutput write: data+offset+got maxLength: length-got]; + 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."]; + } + got += result; } }