You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@thrift.apache.org by dr...@apache.org on 2010/03/09 06:20:22 UTC

svn commit: r920688 - in /incubator/thrift/trunk/lib/cpp/src/transport: TFileTransport.cpp TFileTransport.h

Author: dreiss
Date: Tue Mar  9 05:20:21 2010
New Revision: 920688

URL: http://svn.apache.org/viewvc?rev=920688&view=rev
Log:
cpp: Implement peek() for TFileTransport

Modified:
    incubator/thrift/trunk/lib/cpp/src/transport/TFileTransport.cpp
    incubator/thrift/trunk/lib/cpp/src/transport/TFileTransport.h

Modified: incubator/thrift/trunk/lib/cpp/src/transport/TFileTransport.cpp
URL: http://svn.apache.org/viewvc/incubator/thrift/trunk/lib/cpp/src/transport/TFileTransport.cpp?rev=920688&r1=920687&r2=920688&view=diff
==============================================================================
--- incubator/thrift/trunk/lib/cpp/src/transport/TFileTransport.cpp (original)
+++ incubator/thrift/trunk/lib/cpp/src/transport/TFileTransport.cpp Tue Mar  9 05:20:21 2010
@@ -498,6 +498,22 @@ uint32_t TFileTransport::readAll(uint8_t
   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_) {

Modified: incubator/thrift/trunk/lib/cpp/src/transport/TFileTransport.h
URL: http://svn.apache.org/viewvc/incubator/thrift/trunk/lib/cpp/src/transport/TFileTransport.h?rev=920688&r1=920687&r2=920688&view=diff
==============================================================================
--- incubator/thrift/trunk/lib/cpp/src/transport/TFileTransport.h (original)
+++ incubator/thrift/trunk/lib/cpp/src/transport/TFileTransport.h Tue Mar  9 05:20:21 2010
@@ -181,6 +181,7 @@ class TFileTransport : public TFileReade
 
   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);