[ 
https://issues.apache.org/jira/browse/THRIFT-96?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=12637650#action_12637650
 ] 

Mark Slee commented on THRIFT-96:
---------------------------------

I believe the reason for doing read() instead of peek() with TBufferedTransport 
was a mini-optimization. Since you're buffering the reads anyway, you might as 
well actually pull the data into your buffer if you're going to check for its 
existence. This way, you don't make a peek() call and a read() call, which is 
beneficial in the default case of using a buffered socket. This means 1 syscall 
to read() instead of 2 syscalls.

I'd be fine with switching this to use peek() on the underlying transport, 
since in some cases read() may have side effects that aren't wanted on the 
peek() operation (though I would expect this to be quite rare). But I'd also be 
fine with making the interface contract specify that calls to read() must not 
have any side effects that a peek() call would not also want.

> TSocket.peek fails on FreeBSD
> -----------------------------
>
>                 Key: THRIFT-96
>                 URL: https://issues.apache.org/jira/browse/THRIFT-96
>             Project: Thrift
>          Issue Type: Bug
>          Components: Library (C++)
>         Environment: FreeBSD
>            Reporter: Alexander Shigin
>         Attachments: thrift-freebsd-read.patch, thrift-peek-fix.patch, 
> thrift-peek-fix.patch
>
>
> POSIX says what recv(2) should returns 0 if peer has performed a shutdown. 
> This feature uses in TBufferedTransport 
> {code}
>   bool peek() {
>     if (rBase_ == rBound_) {
>       setReadBuffer(rBuf_.get(), transport_->read(rBuf_.get(), rBufSize_));
>     }
>     return (rBound_ > rBase_);
>   }
> {code}
> The decision works fine on linux, but fails on freebsd. In freebsd, recv 
> returns -1 and errno==ECONNRESET.

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.

Reply via email to