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 \
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 \
-#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
}
// Read another chunk
- readChunk();
+ readFrame();
}
// Hand over whatever we have
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;
// 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;
}
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_);
}
-#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>
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) {
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) {
wBuf_ = new uint8_t[wBufSize_];
}
- ~TChunkedTransport() {
+ ~TFramedTransport() {
if (rBuf_ != NULL) {
delete [] rBuf_;
}
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_
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
<?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.
if ($need > $have) {
$out = $this->rBuf_;
$need -= $have;
- $this->readChunk();
+ $this->readFrame();
}
$give = $need;
/**
* 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];