简体   繁体   English

readdir在安装的CIF目录上花费很长时间

[英]readdir taking a LONG time on mounted cifs dir

I'm running the following code: 我正在运行以下代码:

void EnumerateFolder(std::string folder)
{ 
    DIR* directory;
    struct dirent* entry;

    directory = opendir(folder.c_str());
    if(directory != NULL)
    {
        while((entry = readdir(directory)) != NULL)
        {
            std::cout << entry->d_name;
        }
    }
}

When it gets to a mounted CIFS folder that I have readdir() sometimes takes 15 minutes to return. 当它到达我拥有readdir()的已安装CIFS文件夹时,有时需要15分钟才能返回。 Anyone care to enlighten me as to what is happenening and how I can achieve a friendlier experience? 是否有人想启发我发生了什么以及如何获得更友善的体验? This happens every time I run the code and the computer with the shared folder is offline. 每当我运行代码并且共享文件夹的计算机脱机时,就会发生这种情况。 It also happens arbitrarily(as far as I can tell), perhaps when the computer with the shared folders harddrive is "idle". 它也任意发生(据我所知),也许当带有共享文件夹硬盘的计算机是“空闲”时。

How is the folder mounted you say? 您说的文件夹如何安装?

cat /etc/fstab
//192.168.0.6/MyShare /home/MyUser/MountedShare cifs guest 0 0

192.168.0.6 is running Windows 8, if that matters. 192.168.0.6正在运行Windows 8,如果这很重要。 Thanks! 谢谢!

15 seconds is the standard CIFS Send2 timeout . 标准CIFS Send2超时为15秒。 If you want it to fail faster, you can put a timeo option on the mount options. 如果您希望它更快地失败,则可以在安装选项上放置一个timeo选项。 Specify the timeout in tenths of a second. 以十分之一秒为单位指定超时。

The filesystem doesn't really know why the application wants to read the file. 文件系统并不真正知道应用程序为什么要读取文件。 Fast timeouts could break long-running processes if they were, for example, faulting in pages of executable code. 快速超时可能会破坏长时间运行的进程,例如,如果它们在可执行代码页中出错。 So generally speaking, network filesystems try to mimic the semantics of local filesystems which is to wait for as long as needed for the underlying storage to respond. 因此,一般而言,网络文件系统会尝试模仿本地文件系统的语义,即本地存储系统要等待所需的时间,以便基础存储做出响应。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM