diff --git a/cmake/modules/FindNFS.cmake b/cmake/modules/FindNFS.cmake index c2414a1f434c7..fee3ce62fc253 100644 --- a/cmake/modules/FindNFS.cmake +++ b/cmake/modules/FindNFS.cmake @@ -34,7 +34,10 @@ find_package_handle_standard_args(NFS if(NFS_FOUND) set(NFS_LIBRARIES ${NFS_LIBRARY}) set(NFS_INCLUDE_DIRS ${NFS_INCLUDE_DIR}) - set(NFS_DEFINITIONS -DHAS_FILESYSTEM_NFS=1) + + string(REPLACE "." ";" VERSION_LIST ${NFS_VERSION}) + list(GET VERSION_LIST 0 NFS_VERSION_MAJOR) + set(NFS_DEFINITIONS -DHAS_FILESYSTEM_NFS=1 -DNFS_VERSION=${NFS_VERSION_MAJOR}) if(NOT TARGET NFS::NFS) add_library(NFS::NFS UNKNOWN IMPORTED) diff --git a/xbmc/filesystem/NFSFile.cpp b/xbmc/filesystem/NFSFile.cpp index abbef6805d3fe..3f01002c65511 100644 --- a/xbmc/filesystem/NFSFile.cpp +++ b/xbmc/filesystem/NFSFile.cpp @@ -11,6 +11,9 @@ ////////////////////////////////////////////////////////////////////// #include "NFSFile.h" +#include "ServiceBroker.h" +#include "settings/AdvancedSettings.h" +#include "settings/SettingsComponent.h" #include "threads/SingleLock.h" #include "utils/log.h" #include "utils/StringUtils.h" @@ -178,6 +181,7 @@ int CNfsConnection::getContextForExport(const std::string &exportname) { struct contextTimeout tmp; CSingleLock lock(openContextLock); + setTimeout(m_pNfsContext); tmp.pContext = m_pNfsContext; tmp.lastAccessedTime = XbmcThreads::SystemClockMillis(); m_openContextMap[exportname] = tmp; //add context to list of all contexts @@ -424,6 +428,7 @@ int CNfsConnection::stat(const CURL &url, NFSSTAT *statbuff) if(pTmpContext) { + setTimeout(pTmpContext); //we connect to the directory of the path. This will be the "root" path of this connection then. //So all fileoperations are relative to this mountpoint... nfsRet = nfs_mount(pTmpContext, m_resolvedHostName.c_str(), exportPath.c_str()); @@ -461,6 +466,16 @@ void CNfsConnection::AddIdleConnection() m_IdleTimeout = 180; } + +void CNfsConnection::setTimeout(struct nfs_context *context) +{ +#if NFS_VERSION >= 2 + uint32_t timeout = CServiceBroker::GetSettingsComponent()->GetAdvancedSettings()->m_nfsTimeout; + if (timeout > 0) + nfs_set_timeout(context, timeout); +#endif +} + CNfsConnection gNfsConnection; CNFSFile::CNFSFile() diff --git a/xbmc/filesystem/NFSFile.h b/xbmc/filesystem/NFSFile.h index ea13014a9024c..9e3094eb12491 100644 --- a/xbmc/filesystem/NFSFile.h +++ b/xbmc/filesystem/NFSFile.h @@ -94,6 +94,7 @@ class CNfsConnection : public CCriticalSection void destroyContext(const std::string &exportName); void resolveHost(const CURL &url);//resolve hostname by dnslookup void keepAlive(std::string _exportPath, struct nfsfh *_pFileHandle); + static void setTimeout(struct nfs_context *context); }; extern CNfsConnection gNfsConnection; diff --git a/xbmc/settings/AdvancedSettings.cpp b/xbmc/settings/AdvancedSettings.cpp index 8f0a8327e3c38..3f8020f6ec383 100644 --- a/xbmc/settings/AdvancedSettings.cpp +++ b/xbmc/settings/AdvancedSettings.cpp @@ -454,6 +454,8 @@ void CAdvancedSettings::Initialize() m_userAgent = g_sysinfo.GetUserAgent(); + m_nfsTimeout = 2000; + m_initialized = true; } @@ -534,6 +536,7 @@ void CAdvancedSettings::ParseSettingsFile(const std::string &file) passTag->LinkEndChild(new TiXmlText("*****")); } } + XMLUtils::GetUInt(network, "nfstimeout", m_nfsTimeout, 0, 86400000); } // Dump contents of copied AS.xml to debug log diff --git a/xbmc/settings/AdvancedSettings.h b/xbmc/settings/AdvancedSettings.h index 1de3b00b276dc..f4eba081b7ae5 100644 --- a/xbmc/settings/AdvancedSettings.h +++ b/xbmc/settings/AdvancedSettings.h @@ -386,6 +386,7 @@ class CAdvancedSettings : public ISettingCallback, public ISettingsHandler bool m_openGlDebugging; std::string m_userAgent; + uint32_t m_nfsTimeout; private: void SetExtraLogLevel(const std::vector &components);