From 52155b1860765c63a9a335f0467870ae4cc7a4d0 Mon Sep 17 00:00:00 2001 From: Tatsuhiro Tsujikawa Date: Sun, 25 Dec 2011 23:38:36 +0900 Subject: [PATCH] No retry for close() with EINTR. Also reverted changes in d5ffa253. --- src/AbstractDiskWriter.cc | 18 +++--------------- src/EpollEventPoll.cc | 3 +-- src/KqueueEventPoll.cc | 3 +-- src/MultiDiskAdaptor.cc | 16 ++-------------- src/PortEventPoll.cc | 3 +-- src/RequestGroupMan.cc | 6 +----- src/SocketCore.cc | 2 +- 7 files changed, 10 insertions(+), 41 deletions(-) diff --git a/src/AbstractDiskWriter.cc b/src/AbstractDiskWriter.cc index 50f52701..11888bc0 100644 --- a/src/AbstractDiskWriter.cc +++ b/src/AbstractDiskWriter.cc @@ -59,10 +59,7 @@ AbstractDiskWriter::AbstractDiskWriter(const std::string& filename) AbstractDiskWriter::~AbstractDiskWriter() { - try { - closeFile(); - } catch(...) { - } + closeFile(); } void AbstractDiskWriter::openFile(off_t totalLength) @@ -80,18 +77,9 @@ void AbstractDiskWriter::openFile(off_t totalLength) void AbstractDiskWriter::closeFile() { - if(fd_ >= 0) { - int r; - while((r = close(fd_)) == -1 && errno == EINTR); + if(fd_ != -1) { + close(fd_); fd_ = -1; - if(r == -1) { - int errNum = errno; - throw DL_ABORT_EX3(errNum, - fmt("Failed to close file %s, cause: %s", - filename_.c_str(), - util::safeStrerror(errNum).c_str()), - error_code::FILE_IO_ERROR); - } } } diff --git a/src/EpollEventPoll.cc b/src/EpollEventPoll.cc index 4aff1161..d3c462b5 100644 --- a/src/EpollEventPoll.cc +++ b/src/EpollEventPoll.cc @@ -91,8 +91,7 @@ EpollEventPoll::EpollEventPoll() EpollEventPoll::~EpollEventPoll() { if(epfd_ != -1) { - int r; - while((r = close(epfd_)) == -1 && errno == EINTR); + int r = close(epfd_); int errNum = errno; if(r == -1) { A2_LOG_ERROR(fmt("Error occurred while closing epoll file descriptor" diff --git a/src/KqueueEventPoll.cc b/src/KqueueEventPoll.cc index 688bc91f..e5039943 100644 --- a/src/KqueueEventPoll.cc +++ b/src/KqueueEventPoll.cc @@ -97,8 +97,7 @@ KqueueEventPoll::KqueueEventPoll() KqueueEventPoll::~KqueueEventPoll() { if(kqfd_ != -1) { - int r; - while((r = close(kqfd_)) == -1 && errno == EINTR); + int r = close(kqfd_); int errNum = errno; if(r == -1) { A2_LOG_ERROR(fmt("Error occurred while closing kqueue file descriptor" diff --git a/src/MultiDiskAdaptor.cc b/src/MultiDiskAdaptor.cc index 3cb464ff..17f3198d 100644 --- a/src/MultiDiskAdaptor.cc +++ b/src/MultiDiskAdaptor.cc @@ -297,20 +297,8 @@ void MultiDiskAdaptor::openExistingFile() void MultiDiskAdaptor::closeFile() { - bool ok = true; - for(std::vector >::const_iterator i = - diskWriterEntries_.begin(), eoi = diskWriterEntries_.end(); i != eoi; - ++i) { - try { - (*i)->closeFile(); - } catch(RecoverableException& e) { - A2_LOG_ERROR_EX(EX_EXCEPTION_CAUGHT, e); - ok = false; - } - } - if(!ok) { - throw DL_ABORT_EX("Failed to close some files"); - } + std::for_each(diskWriterEntries_.begin(), diskWriterEntries_.end(), + mem_fun_sh(&DiskWriterEntry::closeFile)); } namespace { diff --git a/src/PortEventPoll.cc b/src/PortEventPoll.cc index db4cb9fb..b95fc44b 100644 --- a/src/PortEventPoll.cc +++ b/src/PortEventPoll.cc @@ -86,8 +86,7 @@ PortEventPoll::PortEventPoll() PortEventPoll::~PortEventPoll() { if(port_ != -1) { - int r; - while((r = close(port_)) == -1 && errno == EINTR); + int r = close(port_); int errNum = errno; if(r == -1) { A2_LOG_ERROR(fmt("Error occurred while closing port %d: %s", diff --git a/src/RequestGroupMan.cc b/src/RequestGroupMan.cc index 6aeae42d..34e9e127 100644 --- a/src/RequestGroupMan.cc +++ b/src/RequestGroupMan.cc @@ -554,11 +554,7 @@ void RequestGroupMan::closeFile() { for(std::deque >::const_iterator itr = requestGroups_.begin(), eoi = requestGroups_.end(); itr != eoi; ++itr) { - try { - (*itr)->closeFile(); - } catch(RecoverableException& e) { - A2_LOG_ERROR_EX(EX_EXCEPTION_CAUGHT, e); - } + (*itr)->closeFile(); } } diff --git a/src/SocketCore.cc b/src/SocketCore.cc index 793dc1bd..59aa2f58 100644 --- a/src/SocketCore.cc +++ b/src/SocketCore.cc @@ -89,7 +89,7 @@ namespace aria2 { #ifdef __MINGW32__ # define CLOSE(X) ::closesocket(X) #else -# define CLOSE(X) while(close(X) == -1 && errno == EINTR) +# define CLOSE(X) close(X) #endif // __MINGW32__ namespace {