Thrift: Rename chunked to framed transports
git-svn-id: https://svn.apache.org/repos/asf/incubator/thrift/trunk@664796 13f79535-47bb-0310-9956-ffa450edef68
diff --git a/lib/cpp/Makefile.am b/lib/cpp/Makefile.am
index 554cb90..4de829f 100644
--- a/lib/cpp/Makefile.am
+++ b/lib/cpp/Makefile.am
@@ -11,7 +11,7 @@
src/concurrency/TimerManager.cc \
src/protocol/TBinaryProtocol.cc \
src/transport/TBufferedTransport.cc \
- src/transport/TChunkedTransport.cc \
+ src/transport/TFramedTransport.cc \
src/transport/TSocket.cc \
src/transport/TServerSocket.cc \
src/server/TSimpleServer.cc \
@@ -48,7 +48,7 @@
include_transportdir = $(include_thriftdir)/transport
include_transport_HEADERS = \
src/transport/TBufferedTransport.h \
- src/transport/TChunkedTransport.h \
+ src/transport/TFramedTransport.h \
src/transport/TNullTransport.h \
src/transport/TServerSocket.h \
src/transport/TServerTransport.h \
diff --git a/lib/cpp/src/transport/TChunkedTransport.cc b/lib/cpp/src/transport/TFramedTransport.cc
similarity index 75%
rename from lib/cpp/src/transport/TChunkedTransport.cc
rename to lib/cpp/src/transport/TFramedTransport.cc
index bb42e38..6ab9dcc 100644
--- a/lib/cpp/src/transport/TChunkedTransport.cc
+++ b/lib/cpp/src/transport/TFramedTransport.cc
@@ -1,9 +1,11 @@
-#include "TChunkedTransport.h"
+#include <transport/TFramedTransport.h>
+#include <netinet/in.h>
+
using std::string;
namespace facebook { namespace thrift { namespace transport {
-uint32_t TChunkedTransport::read(uint8_t* buf, uint32_t len) {
+uint32_t TFramedTransport::read(uint8_t* buf, uint32_t len) {
uint32_t need = len;
// We don't have enough data yet
@@ -16,7 +18,7 @@
}
// Read another chunk
- readChunk();
+ readFrame();
}
// Hand over whatever we have
@@ -30,8 +32,8 @@
return (len - need);
}
-void TChunkedTransport::readChunk() {
- // Get rid of the old chunk
+void TFramedTransport::readFrame() {
+ // Get rid of the old frame
if (rBuf_ != NULL) {
delete [] rBuf_;
rBuf_ = NULL;
@@ -40,19 +42,20 @@
// Read in the next chunk size
int32_t sz;
transport_->readAll((uint8_t*)&sz, 4);
+ sz = (int32_t)ntohl(sz);
if (sz < 0) {
- throw new TTransportException("Next chunk has negative size");
+ throw new TTransportException("Frame size has negative value");
}
- // Read the chunk payload, reset markers
+ // Read the frame payload, reset markers
rBuf_ = new uint8_t[sz];
transport_->readAll(rBuf_, sz);
rPos_ = 0;
rLen_ = sz;
}
-void TChunkedTransport::write(const uint8_t* buf, uint32_t len) {
+void TFramedTransport::write(const uint8_t* buf, uint32_t len) {
if (len == 0) {
return;
}
@@ -81,12 +84,14 @@
wLen_ += len;
}
-void TChunkedTransport::flush() {
- // Write chunk size
+void TFramedTransport::flush() {
+ // Write frame size
int32_t sz = wLen_;
+ sz = (int32_t)htonl(sz);
+
transport_->write((const uint8_t*)&sz, 4);
- // Write chunk body
+ // Write frame body
if (sz > 0) {
transport_->write(wBuf_, wLen_);
}
diff --git a/lib/cpp/src/transport/TChunkedTransport.h b/lib/cpp/src/transport/TFramedTransport.h
similarity index 72%
rename from lib/cpp/src/transport/TChunkedTransport.h
rename to lib/cpp/src/transport/TFramedTransport.h
index ebc2780..f0234ce 100644
--- a/lib/cpp/src/transport/TChunkedTransport.h
+++ b/lib/cpp/src/transport/TFramedTransport.h
@@ -1,5 +1,5 @@
-#ifndef _THRIFT_TRANSPORT_TCHUNKEDTRANSPORT_H_
-#define _THRIFT_TRANSPORT_TCHUNKEDTRANSPORT_H_ 1
+#ifndef _THRIFT_TRANSPORT_TFRAMEDTRANSPORT_H_
+#define _THRIFT_TRANSPORT_TFRAMEDTRANSPORT_H_ 1
#include "TTransport.h"
#include <string>
@@ -10,16 +10,16 @@
using namespace boost;
/**
- * Chunked transport. All writes go into an in-memory buffer until flush is
+ * Framed transport. All writes go into an in-memory buffer until flush is
* called, at which point the transport writes the length of the entire
* binary chunk followed by the data payload. This allows the receiver on the
* other end to always do fixed-length reads.
*
* @author Mark Slee <mcslee@facebook.com>
*/
-class TChunkedTransport : public TTransport {
+class TFramedTransport : public TTransport {
public:
- TChunkedTransport(shared_ptr<TTransport> transport) :
+ TFramedTransport(shared_ptr<TTransport> transport) :
transport_(transport),
rPos_(0), rLen_(0),
wBufSize_(512), wLen_(0) {
@@ -27,7 +27,7 @@
wBuf_ = new uint8_t[wBufSize_];
}
- TChunkedTransport(shared_ptr<TTransport> transport, uint32_t sz) :
+ TFramedTransport(shared_ptr<TTransport> transport, uint32_t sz) :
transport_(transport),
rPos_(0), rLen_(0),
wBufSize_(sz), wLen_(0) {
@@ -35,7 +35,7 @@
wBuf_ = new uint8_t[wBufSize_];
}
- ~TChunkedTransport() {
+ ~TFramedTransport() {
if (rBuf_ != NULL) {
delete [] rBuf_;
}
@@ -73,11 +73,11 @@
uint32_t wLen_;
/**
- * Reads a chunk of input from the underlying stream.
+ * Reads a frame of input from the underlying stream.
*/
- void readChunk();
+ void readFrame();
};
}}} // facebook::thrift::transport
-#endif // #ifndef _THRIFT_TRANSPORT_TCHUNKEDTRANSPORT_H_
+#endif // #ifndef _THRIFT_TRANSPORT_TFRAMEDTRANSPORT_H_
diff --git a/lib/php/Makefile.am b/lib/php/Makefile.am
index c7cd106..0521c77 100644
--- a/lib/php/Makefile.am
+++ b/lib/php/Makefile.am
@@ -6,7 +6,7 @@
transport_SCRIPTS = src/transport/TTransport.php \
src/transport/TBufferedTransport.php \
- src/transport/TChunkedTransport.php \
+ src/transport/TFramedTransport.php \
src/transport/TSocket.php \
src/transport/TSocketPool.php
diff --git a/lib/php/src/transport/TChunkedTransport.php b/lib/php/src/transport/TFramedTransport.php
similarity index 91%
rename from lib/php/src/transport/TChunkedTransport.php
rename to lib/php/src/transport/TFramedTransport.php
index 04fba1f..2d41b40 100644
--- a/lib/php/src/transport/TChunkedTransport.php
+++ b/lib/php/src/transport/TFramedTransport.php
@@ -1,13 +1,13 @@
<?php
/**
- * Chunked transport. Writes and reads data in chunks that are stamped with
+ * Framed transport. Writes and reads data in chunks that are stamped with
* their length.
*
* @package thrift.transport
* @author Mark Slee <mcslee@facebook.com>
*/
-class TChunkedTransport extends TTransport {
+class TFramedTransport extends TTransport {
/**
* Underlying transport object.
@@ -52,7 +52,7 @@
if ($need > $have) {
$out = $this->rBuf_;
$need -= $have;
- $this->readChunk();
+ $this->readFrame();
}
$give = $need;
@@ -70,7 +70,7 @@
/**
* Reads a chunk of data into the internal read buffer.
*/
- private function readChunk() {
+ private function readFrame() {
$buf = $this->transport_->readAll(4);
$val = unpack('N', $buf);
$sz = $val[1];