diff --git a/meshcore/agentcore.c b/meshcore/agentcore.c index 9aa14b1..1b4b98d 100644 --- a/meshcore/agentcore.c +++ b/meshcore/agentcore.c @@ -4028,7 +4028,7 @@ int MeshAgent_AgentMode(MeshAgentHostContainer *agentHost, int paramLen, char ** } else { - if (agentHost->masterDb == NULL) + if (agentHost->masterDb == NULL || ILibSimpleDataStore_IsCacheOnly(agentHost->masterDb)) { void **data = (void**)ILibMemory_SmartAllocate(4 * sizeof(void*)); data[0] = agentHost; @@ -4036,6 +4036,12 @@ int MeshAgent_AgentMode(MeshAgentHostContainer *agentHost, int paramLen, char ** data[2] = param; data[3] = (void*)(uintptr_t)parseCommands; + if (agentHost->masterDb != NULL) + { + ILibSimpleDataStore_Close(agentHost->masterDb); + agentHost->masterDb = NULL; + } + switch (agentHost->dbRetryCount) { case 10: diff --git a/microstack/ILibSimpleDataStore.c b/microstack/ILibSimpleDataStore.c index 6a58f01..8f8040b 100644 --- a/microstack/ILibSimpleDataStore.c +++ b/microstack/ILibSimpleDataStore.c @@ -615,7 +615,13 @@ __EXPORT_TYPE int ILibSimpleDataStore_PutEx(ILibSimpleDataStore dataStore, char* ILibSimpleDataStore_Root *root = (ILibSimpleDataStore_Root*)dataStore; ILibSimpleDataStore_TableEntry *entry; - if (root == NULL) return 0; + if (root == NULL) { return 0; } + if (root->dataFile == NULL) + { + ILibSimpleDataStore_Cached(dataStore, key, keyLen, value, valueLen); + return(0); + } + if (keyLen > 1 && key[keyLen - 1] == 0) { keyLen -= 1; } entry = (ILibSimpleDataStore_TableEntry*)ILibHashtable_Get(root->keyTable, NULL, key, keyLen); ILibSimpleDataStore_SHA384(value, valueLen, hash); // Hash the value @@ -878,3 +884,8 @@ __EXPORT_TYPE int ILibSimpleDataStore_Compact(ILibSimpleDataStore dataStore) free(tmp); // Free the temporary file name return retVal; // Return 1 if we got an error, 0 if everything finished correctly } + +int ILibSimpleDataStore_IsCacheOnly(ILibSimpleDataStore ds) +{ + return(((ILibSimpleDataStore_Root*)ds)->dataFile == NULL ? 1 : 0); +} \ No newline at end of file diff --git a/microstack/ILibSimpleDataStore.h b/microstack/ILibSimpleDataStore.h index 06059a1..9706e57 100644 --- a/microstack/ILibSimpleDataStore.h +++ b/microstack/ILibSimpleDataStore.h @@ -46,6 +46,7 @@ __EXPORT_TYPE ILibSimpleDataStore ILibSimpleDataStore_CreateEx2(char* filePath, #define ILibSimpleDataStore_Create(filePath) ILibSimpleDataStore_CreateEx2(filePath, 0, 0) #define ILibSimpleDataStore_CreateEx(filePath, userExtraMemorySize) ILibSimpleDataStore_CreateEx2(filePath, userExtraMemorySize, 0) #define ILibSimpleDataStore_CreateCachedOnly() ILibSimpleDataStore_Create(NULL) +int ILibSimpleDataStore_IsCacheOnly(ILibSimpleDataStore ds); // Check if the data store exists int ILibSimpleDataStore_Exists(char *filePath);