You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@thrift.apache.org by Matt Ronge <mr...@mronge.com> on 2009/07/02 04:39:01 UTC
Bug fix for the Cocoa transport
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
mronge@mronge.com
http://www.mronge.com
Re: Bug fix for the Cocoa transport
Posted by Michael Greene <mi...@gmail.com>.
Hi Matt,
Thanks for the bug report and fix. It would help if you could file an
issue in JIRA at https://issues.apache.org/jira/browse/THRIFT and
attach your patch as a diff there, where you can sign over the license
to Apache.
Michael
On Wed, Jul 1, 2009 at 9:39 PM, Matt Ronge<mr...@mronge.com> wrote:
> 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
> mronge@mronge.com
> http://www.mronge.com
>
>