diff options
author | fuzzard <fuzzard@users.noreply.github.com> | 2022-07-05 07:52:40 +1000 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-07-05 07:52:40 +1000 |
commit | 9a859b0aaf17ceed86e68d2f2d6e89583a673fa3 (patch) | |
tree | 82fb2d63c73e1cb178eb58cf9afee18c45e30bd1 | |
parent | 2931441937306f09c2c0b9989d69ecfb5e076794 (diff) | |
parent | a0a72dc606c80dac27dd8c3090f97f110f0eb7f9 (diff) |
Merge pull request #21577 from lrusak/nfs-enum-class
CNfsConnection: make getContextForExport return an enum class
-rw-r--r-- | xbmc/filesystem/NFSFile.cpp | 23 | ||||
-rw-r--r-- | xbmc/filesystem/NFSFile.h | 11 |
2 files changed, 20 insertions, 14 deletions
diff --git a/xbmc/filesystem/NFSFile.cpp b/xbmc/filesystem/NFSFile.cpp index 209f44bf09..748e509861 100644 --- a/xbmc/filesystem/NFSFile.cpp +++ b/xbmc/filesystem/NFSFile.cpp @@ -40,11 +40,6 @@ // 6 mins (360s) cached context timeout #define CONTEXT_TIMEOUT 360000 -// return codes for getContextForExport -#define CONTEXT_INVALID 0 // getcontext failed -#define CONTEXT_NEW 1 // new context created -#define CONTEXT_CACHED 2 // context cached and therefore already mounted (no new mount needed) - #if defined(TARGET_WINDOWS) #define S_IRGRP 0 #define S_IROTH 0 @@ -168,9 +163,9 @@ struct nfs_context *CNfsConnection::getContextFromMap(const std::string &exportn return pRet; } -int CNfsConnection::getContextForExport(const std::string &exportname) +CNfsConnection::ContextStatus CNfsConnection::getContextForExport(const std::string& exportname) { - int ret = CONTEXT_INVALID; + CNfsConnection::ContextStatus ret = CNfsConnection::ContextStatus::INVALID; clearMembers(); @@ -193,12 +188,12 @@ int CNfsConnection::getContextForExport(const std::string &exportname) tmp.pContext = m_pNfsContext; tmp.lastAccessedTime = std::chrono::steady_clock::now(); m_openContextMap[exportname] = tmp; //add context to list of all contexts - ret = CONTEXT_NEW; + ret = CNfsConnection::ContextStatus::NEW; } } else { - ret = CONTEXT_CACHED; + ret = CNfsConnection::ContextStatus::CACHED; CLog::Log(LOGDEBUG,"NFS: Using cached context."); } m_lastAccessedTime = std::chrono::steady_clock::now(); @@ -281,14 +276,16 @@ bool CNfsConnection::Connect(const CURL& url, std::string &relativePath) if ((ret && (exportPath != m_exportPath || url.GetHostName() != m_hostName)) || duration.count() > CONTEXT_TIMEOUT) { - int contextRet = getContextForExport(url.GetHostName() + exportPath); + CNfsConnection::ContextStatus contextRet = getContextForExport(url.GetHostName() + exportPath); - if(contextRet == CONTEXT_INVALID)//we need a new context because sharename or hostname has changed + // we need a new context because sharename or hostname has changed + if (contextRet == CNfsConnection::ContextStatus::INVALID) { return false; } - if(contextRet == CONTEXT_NEW) //new context was created - we need to mount it + // new context was created - we need to mount it + if (contextRet == CNfsConnection::ContextStatus::NEW) { //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... @@ -310,7 +307,7 @@ bool CNfsConnection::Connect(const CURL& url, std::string &relativePath) m_readChunkSize = nfs_get_readmax(m_pNfsContext); m_writeChunkSize = nfs_get_writemax(m_pNfsContext); - if(contextRet == CONTEXT_NEW) + if (contextRet == CNfsConnection::ContextStatus::NEW) { CLog::Log(LOGDEBUG, "NFS: chunks: r/w {}/{}", (int)m_readChunkSize, (int)m_writeChunkSize); } diff --git a/xbmc/filesystem/NFSFile.h b/xbmc/filesystem/NFSFile.h index 57b854090e..5e63a54a05 100644 --- a/xbmc/filesystem/NFSFile.h +++ b/xbmc/filesystem/NFSFile.h @@ -74,6 +74,13 @@ public: const std::string GetContextMapId() const {return m_hostName + m_exportPath;} private: + enum class ContextStatus + { + INVALID, + NEW, + CACHED + }; + struct nfs_context *m_pNfsContext;//current nfs context std::string m_exportPath;//current connected export path std::string m_hostName;//current connected host @@ -92,7 +99,9 @@ private: void clearMembers(); struct nfs_context *getContextFromMap(const std::string &exportname, bool forceCacheHit = false); - int getContextForExport(const std::string &exportname);//get context for given export and add to open contexts map - sets m_pNfsContext (my return a already mounted cached context) + + // get context for given export and add to open contexts map - sets m_pNfsContext (may return an already mounted cached context) + ContextStatus getContextForExport(const std::string& exportname); void destroyOpenContexts(); void destroyContext(const std::string &exportName); void resolveHost(const CURL &url);//resolve hostname by dnslookup |