You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@thrift.apache.org by ge...@apache.org on 2009/07/21 17:34:07 UTC

svn commit: r796351 - /incubator/thrift/trunk/lib/cocoa/src/transport/TNSStreamTransport.m

Author: geechorama
Date: Tue Jul 21 15:34:07 2009
New Revision: 796351

URL: http://svn.apache.org/viewvc?rev=796351&view=rev
Log:
THRIFT-533.  Fix write:offset:length: to ensure all requested data is written.

Modified:
    incubator/thrift/trunk/lib/cocoa/src/transport/TNSStreamTransport.m

Modified: incubator/thrift/trunk/lib/cocoa/src/transport/TNSStreamTransport.m
URL: http://svn.apache.org/viewvc/incubator/thrift/trunk/lib/cocoa/src/transport/TNSStreamTransport.m?rev=796351&r1=796350&r2=796351&view=diff
==============================================================================
--- incubator/thrift/trunk/lib/cocoa/src/transport/TNSStreamTransport.m (original)
+++ incubator/thrift/trunk/lib/cocoa/src/transport/TNSStreamTransport.m Tue Jul 21 15:34:07 2009
@@ -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;
   }
 }