From 504303840bbf33fc97740a6eadd27d4bff0b560e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A9=20Kapelrud?= Date: Fri, 1 Apr 2016 17:34:42 +0200 Subject: [PATCH 1/2] Inotify: invalid post occuring at shutdown. - Got rid of the use of iostream. --- .../inotify/basic_dir_monitor_service.hpp | 26 ++----------------- 1 file changed, 2 insertions(+), 24 deletions(-) diff --git a/include/dir_monitor/inotify/basic_dir_monitor_service.hpp b/include/dir_monitor/inotify/basic_dir_monitor_service.hpp index 1d8d2d3..acf90c8 100755 --- a/include/dir_monitor/inotify/basic_dir_monitor_service.hpp +++ b/include/dir_monitor/inotify/basic_dir_monitor_service.hpp @@ -90,28 +90,8 @@ class basic_dir_monitor_service dir_monitor_event ev; if (impl) ev = impl->popfront_event(ec); - PostAndWait(ec, ev); - } - - protected: - void PostAndWait(const boost::system::error_code ec, const dir_monitor_event& ev) const - { - std::mutex post_mutex; - std::condition_variable post_condition_variable; - bool post_cancel = false; - - this->io_service_.post( - [&] - { - handler_(ec, ev); - std::lock_guard lock(post_mutex); - post_cancel = true; - post_condition_variable.notify_one(); - } - ); - std::unique_lock lock(post_mutex); - while (!post_cancel) - post_condition_variable.wait(lock); + if(ec != boost::asio::error::operation_aborted) + this->io_service_.post(boost::asio::detail::bind_handler(handler_, ec, ev)); } private: @@ -141,8 +121,6 @@ class basic_dir_monitor_service // destroyed _after_ the thread is finished (not that the thread tries to access // instance properties which don't exist anymore). async_monitor_thread_.join(); - - std::cout << "shutdown complete" << std::endl; } boost::asio::io_service async_monitor_io_service_; From a6ee49bdd5bdd130fd95812be0ebf7391e412f18 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A9=20Kapelrud?= Date: Fri, 1 Apr 2016 14:11:02 +0200 Subject: [PATCH 2/2] Translate IN_ATTRIB to IN_MODIFY Inotify has a separate event for attribute changes (modification times etc.). Translate this to a modification event, to be consistent with the windows implementation. --- include/dir_monitor/inotify/dir_monitor_impl.hpp | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/include/dir_monitor/inotify/dir_monitor_impl.hpp b/include/dir_monitor/inotify/dir_monitor_impl.hpp index a6b83c8..63e782f 100644 --- a/include/dir_monitor/inotify/dir_monitor_impl.hpp +++ b/include/dir_monitor/inotify/dir_monitor_impl.hpp @@ -41,7 +41,7 @@ class dir_monitor_impl void add_directory(const std::string &dirname) { - int wd = inotify_add_watch(fd_, dirname.c_str(), IN_CREATE | IN_DELETE | IN_MODIFY | IN_MOVED_FROM | IN_MOVED_TO); + int wd = inotify_add_watch(fd_, dirname.c_str(), IN_CREATE | IN_DELETE | IN_ATTRIB | IN_MODIFY | IN_MOVED_FROM | IN_MOVED_TO); if (wd == -1) { boost::system::system_error e(boost::system::error_code(errno, boost::system::get_system_category()), "boost::asio::dir_monitor_impl::add_directory: inotify_add_watch failed"); @@ -159,7 +159,9 @@ class dir_monitor_impl { case IN_CREATE: type = dir_monitor_event::added; break; case IN_DELETE: type = dir_monitor_event::removed; break; - case IN_MODIFY: type = dir_monitor_event::modified; break; + case IN_ATTRIB: + case IN_MODIFY: type = dir_monitor_event::modified; + break; case IN_MOVED_FROM: type = dir_monitor_event::renamed_old_name; break; case IN_MOVED_TO: type = dir_monitor_event::renamed_new_name; break; case IN_CREATE | IN_ISDIR: