【问题标题】:Poco::DirectoryWatcher does not handle network connection lostPoco::DirectoryWatcher 不处理网络连接丢失
【发布时间】:2021-03-11 10:14:49
【问题描述】:

在 Windows 上使用 Poco 1.10.1,我尝试了以下代码:

try
{
   Poco::DirectoryWatcher dw( "\\test"); getch();
}
catch( const Poco::Exception& e)
{
    std::cerr << e.displayText();
}

但如果在 DirectoryWatcher() 运行时删除了“\test”,则不会收到异常。 此外,如果“\test”驻留在映射驱动器上并且网络连接丢失并重新建立, 从那一刻起不再收到任何事件。

我也尝试通过 Poco::ErrorHandler::set() 提供我自己的错误处理程序 - 但这并没有改变。

有什么提示吗? t

【问题讨论】:

    标签: windows visual-c++ poco-libraries


    【解决方案1】:

    DirectoryWatcher 内部有一些异常被抛出和处理。您可以通过注册代表的方式收到这些异常的通知,类似于您注册itemAdded 的方式。

    查看this question中的基本代码。

    然后你可以添加一个 scanError 委托

       watcher->scanError += Poco::delegate(this, &Monitor::onScanError);
    

       void onScanError(const Poco::Exception& exc) {
          std::cout << "Exc: " << exc.what() << std::endl;
       }
    

    然后您将分别收到Poco::FileAccessDeniedExceptionPoco::PathNotFoundException 的通知。

    【讨论】:

      猜你喜欢
      • 2013-09-02
      • 1970-01-01
      • 1970-01-01
      • 2013-09-02
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-12-27
      相关资源
      最近更新 更多