From fc8a1e04693c95ccad02bfa760064606c2358f5a Mon Sep 17 00:00:00 2001 From: Mark Slee Date: Tue, 14 Oct 2008 22:00:36 +0000 Subject: [PATCH] THRIFT-169: Fixes framed/buffered transport state on underlying flush failure git-svn-id: https://svn.apache.org/repos/asf/incubator/thrift/trunk@704710 13f79535-47bb-0310-9956-ffa450edef68 --- lib/php/src/transport/TBufferedTransport.php | 7 ++++++- lib/php/src/transport/TFramedTransport.php | 6 +++++- 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/lib/php/src/transport/TBufferedTransport.php b/lib/php/src/transport/TBufferedTransport.php index eb76167e..26825693 100644 --- a/lib/php/src/transport/TBufferedTransport.php +++ b/lib/php/src/transport/TBufferedTransport.php @@ -131,8 +131,13 @@ class TBufferedTransport extends TTransport { public function write($buf) { $this->wBuf_ .= $buf; if (strlen($this->wBuf_) >= $this->wBufSize_) { - $this->transport_->write($this->wBuf_); + $out = $this->wBuf_; + + // Note that we clear the internal wBuf_ prior to the underlying write + // to ensure we're in a sane state (i.e. internal buffer cleaned) + // if the underlying write throws up an exception $this->wBuf_ = ''; + $this->transport_->write($out); } } diff --git a/lib/php/src/transport/TFramedTransport.php b/lib/php/src/transport/TFramedTransport.php index e2f8d6bc..2c7a3443 100644 --- a/lib/php/src/transport/TFramedTransport.php +++ b/lib/php/src/transport/TFramedTransport.php @@ -158,9 +158,13 @@ class TFramedTransport extends TTransport { $out = pack('N', strlen($this->wBuf_)); $out .= $this->wBuf_; + + // Note that we clear the internal wBuf_ prior to the underlying write + // to ensure we're in a sane state (i.e. internal buffer cleaned) + // if the underlying write throws up an exception + $this->wBuf_ = ''; $this->transport_->write($out); $this->transport_->flush(); - $this->wBuf_ = ''; } } -- 2.17.1