From: David Reiss Date: Tue, 9 Mar 2010 05:20:21 +0000 (+0000) Subject: cpp: Implement peek() for TFileTransport X-Git-Tag: 0.3.0~71 X-Git-Url: https://source.supwisdom.com/gerrit/gitweb?a=commitdiff_plain;h=ccd4bdb2aebee869c537c8a38fd1c00e9ac706b3;p=common%2Fthrift.git cpp: Implement peek() for TFileTransport git-svn-id: https://svn.apache.org/repos/asf/incubator/thrift/trunk@920688 13f79535-47bb-0310-9956-ffa450edef68 --- diff --git a/lib/cpp/src/transport/TFileTransport.cpp b/lib/cpp/src/transport/TFileTransport.cpp index 578bed71..0b41694e 100644 --- a/lib/cpp/src/transport/TFileTransport.cpp +++ b/lib/cpp/src/transport/TFileTransport.cpp @@ -498,6 +498,22 @@ uint32_t TFileTransport::readAll(uint8_t* buf, uint32_t len) { return have; } +bool TFileTransport::peek() { + // check if there is an event ready to be read + if (!currentEvent_) { + currentEvent_ = readEvent(); + } + + // did not manage to read an event from the file. This could have happened + // if the timeout expired or there was some other error + if (!currentEvent_) { + return false; + } + + // check if there is anything to read + return (currentEvent_->eventSize_ - currentEvent_->eventBuffPos_) > 0; +} + uint32_t TFileTransport::read(uint8_t* buf, uint32_t len) { // check if there an event is ready to be read if (!currentEvent_) { diff --git a/lib/cpp/src/transport/TFileTransport.h b/lib/cpp/src/transport/TFileTransport.h index 7a6984a8..30d3a9bd 100644 --- a/lib/cpp/src/transport/TFileTransport.h +++ b/lib/cpp/src/transport/TFileTransport.h @@ -181,6 +181,7 @@ class TFileTransport : public TFileReaderTransport, uint32_t readAll(uint8_t* buf, uint32_t len); uint32_t read(uint8_t* buf, uint32_t len); + bool peek(); // log-file specific functions void seekToChunk(int32_t chunk);