Commit 43992908 authored by jan.koester's avatar jan.koester
Browse files

tes

parent 87f9bcea
Loading
Loading
Loading
Loading
Loading
+1 −4
Changes for src/api.cpp: 1 added line, 4 removed lines.
Original line number Diff line number Diff line
@@ -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);
                }
            }
        }
+17 −5
Changes for src/backends/file.cpp: 17 added lines, 5 removed lines.
Original line number Diff line number Diff line
@@ -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){
@@ -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(
@@ -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;
        }

@@ -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;
        }

+10 −0
Changes for src/client.cpp: 10 added lines, 0 removed lines.
Original line number Diff line number Diff line
@@ -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;
}
+1 −0
Changes for src/client.h: 1 added line, 0 removed lines.
Original line number Diff line number Diff line
@@ -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();