Loading src/api.cpp +1 −4 Changes for src/api.cpp: 1 added line, 4 removed lines. Original line number Diff line number Diff line Loading @@ -234,10 +234,7 @@ public: const char* id = json_object_get_string(val); ::uuid::uuid cid; if (cid.parse(id) != 0) return nullptr; for (ClientConnections* curcon = AuthClient.ConnectionData(); curcon; curcon = curcon->next()) { if (*curcon == cid) return curcon; } return AuthClient.findConnection(cid); } } } Loading src/backends/file.cpp +17 −5 Changes for src/backends/file.cpp: 17 added lines, 5 removed lines. Original line number Diff line number Diff line Loading @@ -142,6 +142,13 @@ authdb::File::File(const char* path,size_t version,const char *domain){ } authdb::File::~File(){ #ifdef Windows if(_FileDes != INVALID_HANDLE_VALUE) CloseHandle(_FileDes); #else if(_FileDes >= 0) close(_FileDes); #endif } void authdb::File::read(unsigned char* src, size_t srcsize){ Loading Loading @@ -234,7 +241,7 @@ void authdb::File::write(const unsigned char* dest, size_t destsize){ void authdb::File::lock(){ #ifdef Windows for (;;) { for (int attempt=0;;++attempt) { // Step 1: Open or create the lock file. // We use a share mode of 0 to get an exclusive handle, which is a form of locking in itself. _LockDes = CreateFileA( Loading @@ -247,9 +254,10 @@ void authdb::File::lock(){ NULL); // hTemplateFile if (_LockDes == INVALID_HANDLE_VALUE) { // If the file could not be opened/created, we continue the loop to retry, // mimicking the Unix code's behavior. A real-world application might // add a delay here to prevent a tight spin-loop. if (attempt > 100) { throw AuthBackendError("couldn't open lockfile: too many retries"); } Sleep(10); continue; } Loading Loading @@ -286,12 +294,16 @@ void authdb::File::lock(){ } } #else for(;;){ for(int attempt=0;;++attempt){ mode_t m = umask( 0 ); _LockDes = open( _lockFile.c_str(), O_RDWR|O_CREAT, 0666 ); umask( m ); if(_LockDes<0){ if(attempt > 100){ throw AuthBackendError("couldn't open lockfile: too many retries"); } usleep(10000); continue; } Loading src/client.cpp +10 −0 Changes for src/client.cpp: 10 added lines, 0 removed lines. Original line number Diff line number Diff line Loading @@ -274,6 +274,16 @@ bool authdb::Client::checkConnection(const uuid::uuid &conid) const{ return false; } authdb::ClientConnections *authdb::Client::findConnection(const uuid::uuid &conid){ std::lock_guard<std::mutex> guard(_lockConnection); for(ClientConnections *curdat=_firstConnection; curdat; curdat=curdat->_next){ if(curdat->_sessionId==conid){ return curdat; } } return nullptr; } authdb::ClientConnections * authdb::Client::ConnectionData(){ return _firstConnection; } src/client.h +1 −0 Changes for src/client.h: 1 added line, 0 removed lines. Original line number Diff line number Diff line Loading @@ -95,6 +95,7 @@ namespace authdb { void delConnection(const uuid::uuid &conid); bool checkConnection(const uuid::uuid &conid) const; ClientConnections *findConnection(const uuid::uuid &conid); ClientConnections *ConnectionData(); Loading Loading
src/api.cpp +1 −4 Changes for src/api.cpp: 1 added line, 4 removed lines. Original line number Diff line number Diff line Loading @@ -234,10 +234,7 @@ public: const char* id = json_object_get_string(val); ::uuid::uuid cid; if (cid.parse(id) != 0) return nullptr; for (ClientConnections* curcon = AuthClient.ConnectionData(); curcon; curcon = curcon->next()) { if (*curcon == cid) return curcon; } return AuthClient.findConnection(cid); } } } Loading
src/backends/file.cpp +17 −5 Changes for src/backends/file.cpp: 17 added lines, 5 removed lines. Original line number Diff line number Diff line Loading @@ -142,6 +142,13 @@ authdb::File::File(const char* path,size_t version,const char *domain){ } authdb::File::~File(){ #ifdef Windows if(_FileDes != INVALID_HANDLE_VALUE) CloseHandle(_FileDes); #else if(_FileDes >= 0) close(_FileDes); #endif } void authdb::File::read(unsigned char* src, size_t srcsize){ Loading Loading @@ -234,7 +241,7 @@ void authdb::File::write(const unsigned char* dest, size_t destsize){ void authdb::File::lock(){ #ifdef Windows for (;;) { for (int attempt=0;;++attempt) { // Step 1: Open or create the lock file. // We use a share mode of 0 to get an exclusive handle, which is a form of locking in itself. _LockDes = CreateFileA( Loading @@ -247,9 +254,10 @@ void authdb::File::lock(){ NULL); // hTemplateFile if (_LockDes == INVALID_HANDLE_VALUE) { // If the file could not be opened/created, we continue the loop to retry, // mimicking the Unix code's behavior. A real-world application might // add a delay here to prevent a tight spin-loop. if (attempt > 100) { throw AuthBackendError("couldn't open lockfile: too many retries"); } Sleep(10); continue; } Loading Loading @@ -286,12 +294,16 @@ void authdb::File::lock(){ } } #else for(;;){ for(int attempt=0;;++attempt){ mode_t m = umask( 0 ); _LockDes = open( _lockFile.c_str(), O_RDWR|O_CREAT, 0666 ); umask( m ); if(_LockDes<0){ if(attempt > 100){ throw AuthBackendError("couldn't open lockfile: too many retries"); } usleep(10000); continue; } Loading
src/client.cpp +10 −0 Changes for src/client.cpp: 10 added lines, 0 removed lines. Original line number Diff line number Diff line Loading @@ -274,6 +274,16 @@ bool authdb::Client::checkConnection(const uuid::uuid &conid) const{ return false; } authdb::ClientConnections *authdb::Client::findConnection(const uuid::uuid &conid){ std::lock_guard<std::mutex> guard(_lockConnection); for(ClientConnections *curdat=_firstConnection; curdat; curdat=curdat->_next){ if(curdat->_sessionId==conid){ return curdat; } } return nullptr; } authdb::ClientConnections * authdb::Client::ConnectionData(){ return _firstConnection; }
src/client.h +1 −0 Changes for src/client.h: 1 added line, 0 removed lines. Original line number Diff line number Diff line Loading @@ -95,6 +95,7 @@ namespace authdb { void delConnection(const uuid::uuid &conid); bool checkConnection(const uuid::uuid &conid) const; ClientConnections *findConnection(const uuid::uuid &conid); ClientConnections *ConnectionData(); Loading