-- Check all system call return values

Summary:
-- Throw TTransportException if a system call fails

Reviewed By: Mark Slee


git-svn-id: https://svn.apache.org/repos/asf/incubator/thrift/trunk@664890 13f79535-47bb-0310-9956-ffa450edef68
diff --git a/lib/cpp/src/transport/TBufferedFileWriter.cpp b/lib/cpp/src/transport/TBufferedFileWriter.cpp
index 39e2074..063c9fe 100644
--- a/lib/cpp/src/transport/TBufferedFileWriter.cpp
+++ b/lib/cpp/src/transport/TBufferedFileWriter.cpp
@@ -64,7 +64,10 @@
   if (fd_ > 0) {
     // TODO: should there be a flush here?
     fprintf(stderr, "error, current file (%s) not closed\n", filename_.c_str());
-    ::close(fd_);
+    if(-1 == ::close(fd_)) {
+      perror("TFileTransport: error in file close");
+      throw TTransportException("TFileTransport: error in file close");
+    }
   }
 
   if (fd) {
@@ -102,7 +105,9 @@
 
   // close logfile
   if (fd_ > 0) {
-    ::close(fd_);
+    if(-1 == ::close(fd_)) {
+      perror("TFileTransport: error in file close");
+    }
   }
 }
 
@@ -251,8 +256,8 @@
     if(closing_) {
       if(-1 == ::close(fd_)) {
         perror("TFileTransport: error in close");
+        throw TTransportException("TFileTransport: error in file close");
       }
-      throw TTransportException("error in file close");
       fd_ = 0;
       return;
     }
@@ -317,7 +322,6 @@
     if(outEvent->eventSize_ > 0) {
       if(-1 == ::write(fd_, outEvent->eventBuff_, outEvent->eventSize_)) {
         perror("TFileTransport: error while writing event");
-        // TODO: should this trigger an exception or simply continue?
         throw TTransportException("TFileTransport: error while writing event");
       }
 
@@ -431,7 +435,6 @@
       if (readState_.bufferLen_ == -1) {
         readState_.resetAllValues();
         perror("TFileTransport: error while reading from file");
-        // TODO: should this trigger an exception or simply continue?
         throw TTransportException("TFileTransport: error while reading from file");
       } else if (readState_.bufferLen_ == 0) {  // EOF
         // wait indefinitely if there is no timeout
@@ -574,7 +577,6 @@
   readState_.resetAllValues();
   if (offset_ == -1) {
     perror("TFileTransport: lseek error in seekToChunk");
-    // TODO: should this trigger an exception or simply continue?
     throw TTransportException("TFileTransport: lseek error in seekToChunk");
   }