From: Aditya Agarwal Date: Sat, 9 Dec 2006 00:47:03 +0000 (+0000) Subject: -- Check all system call return values X-Git-Tag: 0.2.0~1582 X-Git-Url: https://source.supwisdom.com/gerrit/gitweb?a=commitdiff_plain;h=0c341a1332a11120e292c16b0a4dec742800518f;p=common%2Fthrift.git -- 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 39e20745..063c9fe4 100644 --- a/lib/cpp/src/transport/TBufferedFileWriter.cpp +++ b/lib/cpp/src/transport/TBufferedFileWriter.cpp @@ -64,7 +64,10 @@ void TFileTransport::resetOutputFile(int fd, string filename, long long offset) 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 @@ TFileTransport::~TFileTransport() { // close logfile if (fd_ > 0) { - ::close(fd_); + if(-1 == ::close(fd_)) { + perror("TFileTransport: error in file close"); + } } } @@ -251,8 +256,8 @@ void TFileTransport::writerThread() { 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 @@ void TFileTransport::writerThread() { 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 @@ bool TFileTransport::readEvent() { 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 @@ void TFileTransport::seekToChunk(int32_t chunk) { 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"); }