No retry for close() with EINTR. Also reverted changes in d5ffa253.

pull/8/head
Tatsuhiro Tsujikawa 2011-12-25 23:38:36 +09:00
parent 8865001f01
commit 52155b1860
7 changed files with 10 additions and 41 deletions

View File

@ -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);
}
}
}

View File

@ -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"

View File

@ -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"

View File

@ -297,20 +297,8 @@ void MultiDiskAdaptor::openExistingFile()
void MultiDiskAdaptor::closeFile()
{
bool ok = true;
for(std::vector<SharedHandle<DiskWriterEntry> >::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 {

View File

@ -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",

View File

@ -554,11 +554,7 @@ void RequestGroupMan::closeFile()
{
for(std::deque<SharedHandle<RequestGroup> >::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();
}
}

View File

@ -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 {