From 3f23af80c3bde0dc9fac2a8a6f893fd64118c94f Mon Sep 17 00:00:00 2001 From: Aleksandar Fabijanic Date: Sat, 8 Sep 2012 02:54:42 +0000 Subject: [PATCH] porting rev. 1994 from 1.4.4 --- CHANGELOG | 1 + Foundation/src/DirectoryWatcher.cpp | 178 ++++++++++++++-------------- Foundation/src/File_UNIX.cpp | 28 ++--- 3 files changed, 104 insertions(+), 103 deletions(-) diff --git a/CHANGELOG b/CHANGELOG index 1eb8e5267..0da4adc57 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -46,6 +46,7 @@ Release 1.4.4p1 (2012-??-??) - fixed SF# 3558012 Compilation fails when building with -ansi or -std=c++0x - fixed SF# 3563517 Get rid of loss-of-precision warnings on x64 MacOS - fixed SF#3562244: Portability fix for AF_LINK +- fixed SF #3562400: DatagramSocketImpl'comment is faile Release 1.4.4 (2012-09-03) diff --git a/Foundation/src/DirectoryWatcher.cpp b/Foundation/src/DirectoryWatcher.cpp index f943e54fd..e51191609 100644 --- a/Foundation/src/DirectoryWatcher.cpp +++ b/Foundation/src/DirectoryWatcher.cpp @@ -48,10 +48,10 @@ #include #include #include -#elif POCO_OS == POCO_OS_MAC_OS_X || POCO_OS == POCO_OS_FREE_BSD - #include - #include - #include +#elif POCO_OS == POCO_OS_MAC_OS_X || POCO_OS == POCO_OS_FREE_BSD + #include + #include + #include #include #endif #include @@ -396,101 +396,101 @@ private: }; -#elif POCO_OS == POCO_OS_MAC_OS_X || POCO_OS == POCO_OS_FREE_BSD - - -class BSDDirectoryWatcherStrategy: public DirectoryWatcherStrategy -{ -public: - BSDDirectoryWatcherStrategy(DirectoryWatcher& owner): - DirectoryWatcherStrategy(owner), - _queueFD(-1), - _dirFD(-1), - _stopped(false) - { - _dirFD = open(owner.directory().path().c_str(), O_EVTONLY); - if (_dirFD < 0) throw Poco::FileNotFoundException(owner.directory().path()); - _queueFD = kqueue(); - if (_queueFD < 0) - { - close(_dirFD); - throw Poco::SystemException("Cannot create kqueue", errno); - } - } - - ~BSDDirectoryWatcherStrategy() - { - close(_dirFD); - close(_queueFD); - } - - void run() - { - Poco::Timestamp lastScan; - ItemInfoMap entries; - scan(entries); - - while (!_stopped) - { - struct timespec timeout; - timeout.tv_sec = 0; - timeout.tv_nsec = 200000000; - unsigned eventFilter = NOTE_WRITE; - struct kevent event; - struct kevent eventData; - EV_SET(&event, _dirFD, EVFILT_VNODE, EV_ADD | EV_CLEAR, eventFilter, 0, 0); - int nEvents = kevent(_queueFD, &event, 1, &eventData, 1, &timeout); - if (nEvents < 0 || eventData.flags == EV_ERROR) - { - try - { - FileImpl::handleLastErrorImpl(owner().directory().path()); - } - catch (Poco::Exception& exc) - { - owner().scanError(&owner(), exc); - } - } - else if (nEvents > 0 || ((owner().eventMask() & DirectoryWatcher::DW_ITEM_MODIFIED) && lastScan.isElapsed(owner().scanInterval()*1000000))) - { - ItemInfoMap newEntries; - scan(newEntries); - compare(entries, newEntries); - std::swap(entries, newEntries); - lastScan.update(); - } - } - } - - void stop() - { - _stopped = true; - } - - bool supportsMoveEvents() const - { - return false; - } - -private: - int _queueFD; - int _dirFD; - bool _stopped; +#elif POCO_OS == POCO_OS_MAC_OS_X || POCO_OS == POCO_OS_FREE_BSD + + +class BSDDirectoryWatcherStrategy: public DirectoryWatcherStrategy +{ +public: + BSDDirectoryWatcherStrategy(DirectoryWatcher& owner): + DirectoryWatcherStrategy(owner), + _queueFD(-1), + _dirFD(-1), + _stopped(false) + { + _dirFD = open(owner.directory().path().c_str(), O_EVTONLY); + if (_dirFD < 0) throw Poco::FileNotFoundException(owner.directory().path()); + _queueFD = kqueue(); + if (_queueFD < 0) + { + close(_dirFD); + throw Poco::SystemException("Cannot create kqueue", errno); + } + } + + ~BSDDirectoryWatcherStrategy() + { + close(_dirFD); + close(_queueFD); + } + + void run() + { + Poco::Timestamp lastScan; + ItemInfoMap entries; + scan(entries); + + while (!_stopped) + { + struct timespec timeout; + timeout.tv_sec = 0; + timeout.tv_nsec = 200000000; + unsigned eventFilter = NOTE_WRITE; + struct kevent event; + struct kevent eventData; + EV_SET(&event, _dirFD, EVFILT_VNODE, EV_ADD | EV_CLEAR, eventFilter, 0, 0); + int nEvents = kevent(_queueFD, &event, 1, &eventData, 1, &timeout); + if (nEvents < 0 || eventData.flags == EV_ERROR) + { + try + { + FileImpl::handleLastErrorImpl(owner().directory().path()); + } + catch (Poco::Exception& exc) + { + owner().scanError(&owner(), exc); + } + } + else if (nEvents > 0 || ((owner().eventMask() & DirectoryWatcher::DW_ITEM_MODIFIED) && lastScan.isElapsed(owner().scanInterval()*1000000))) + { + ItemInfoMap newEntries; + scan(newEntries); + compare(entries, newEntries); + std::swap(entries, newEntries); + lastScan.update(); + } + } + } + + void stop() + { + _stopped = true; + } + + bool supportsMoveEvents() const + { + return false; + } + +private: + int _queueFD; + int _dirFD; + bool _stopped; }; #else -class DefaultDirectoryWatcherStrategy: public DirectoryWatcherStrategy +class PollingDirectoryWatcherStrategy: public DirectoryWatcherStrategy { public: - DefaultDirectoryWatcherStrategy(DirectoryWatcher& owner): + PollingDirectoryWatcherStrategy(DirectoryWatcher& owner): DirectoryWatcherStrategy(owner) { } - ~DefaultDirectoryWatcherStrategy() + ~PollingDirectoryWatcherStrategy() { } @@ -583,10 +583,10 @@ void DirectoryWatcher::init() _pStrategy = new WindowsDirectoryWatcherStrategy(*this); #elif POCO_OS == POCO_OS_LINUX _pStrategy = new LinuxDirectoryWatcherStrategy(*this); -#elif POCO_OS == POCO_OS_MAC_OS_X || POCO_OS == POCO_OS_FREE_BSD +#elif POCO_OS == POCO_OS_MAC_OS_X || POCO_OS == POCO_OS_FREE_BSD _pStrategy = new BSDDirectoryWatcherStrategy(*this); #else - _pStrategy = new DefaultDirectoryWatcherStrategy(*this); + _pStrategy = new PollingDirectoryWatcherStrategy(*this); #endif _thread.start(*this); } diff --git a/Foundation/src/File_UNIX.cpp b/Foundation/src/File_UNIX.cpp index c3fd94494..7fb307c46 100644 --- a/Foundation/src/File_UNIX.cpp +++ b/Foundation/src/File_UNIX.cpp @@ -433,36 +433,36 @@ void FileImpl::handleLastErrorImpl(const std::string& path) switch (errno) { case EIO: - throw IOException(path); + throw IOException(path, errno); case EPERM: - throw FileAccessDeniedException("insufficient permissions", path); + throw FileAccessDeniedException("insufficient permissions", path, errno); case EACCES: - throw FileAccessDeniedException(path); + throw FileAccessDeniedException(path, errno); case ENOENT: - throw FileNotFoundException(path); + throw FileNotFoundException(path, errno); case ENOTDIR: - throw OpenFileException("not a directory", path); + throw OpenFileException("not a directory", path, errno); case EISDIR: - throw OpenFileException("not a file", path); + throw OpenFileException("not a file", path, errno); case EROFS: - throw FileReadOnlyException(path); + throw FileReadOnlyException(path, errno); case EEXIST: - throw FileExistsException(path); + throw FileExistsException(path, errno); case ENOSPC: - throw FileException("no space left on device", path); + throw FileException("no space left on device", path, errno); case EDQUOT: - throw FileException("disk quota exceeded", path); + throw FileException("disk quota exceeded", path, errno); #if !defined(_AIX) case ENOTEMPTY: - throw FileException("directory not empty", path); + throw FileException("directory not empty", path, errno); #endif case ENAMETOOLONG: - throw PathSyntaxException(path); + throw PathSyntaxException(path, errno); case ENFILE: case EMFILE: - throw FileException("too many open files", path); + throw FileException("too many open files", path, errno); default: - throw FileException(std::strerror(errno), path); + throw FileException(std::strerror(errno), path, errno); } }