diff options
| author | Jesper Jensen <jesper@jnsn.dev> | 2025-07-18 10:50:40 +0200 |
|---|---|---|
| committer | Jesper Jensen <jesper@jnsn.dev> | 2025-07-18 10:50:40 +0200 |
| commit | e7692dd1156bb3abbb19aa8a1f0f35417733c91f (patch) | |
| tree | 881489e1871445e4abeedbad4ef54416789c0d22 | |
| parent | 69528489cddd27b4d4b9411d00b60cccc175b0e8 (diff) | |
Unify the error handling
| -rw-r--r-- | src/api.c | 18 |
1 files changed, 8 insertions, 10 deletions
@@ -189,15 +189,13 @@ static enum MHD_Result handler( if(conn->state == OP_PENDING) { if(!conn->target_set) { - pthread_mutex_unlock(&api->dht->mutex); - return MHD_NO; + goto err; } if(api->dht->lookup.state != OP_EMPTY) { - pthread_mutex_unlock(&api->dht->mutex); // @COMPL We should return some nice error message to the user // here about how they lost a race - return MHD_NO; + goto err; } // Start a lookup @@ -206,26 +204,26 @@ static enum MHD_Result handler( prom_gauge_set(lookup_state, api->dht->lookup.state, NULL); } else if(conn->state == OP_EMPTY) { if(conn->target_set) { - pthread_mutex_unlock(&api->dht->mutex); - return MHD_NO; + goto err; } if(api->dht->lookup.state != OP_COMPLETED) { - pthread_mutex_unlock(&api->dht->mutex); // @COMPL We should return some nice error message to the user // here about how they lost a race - return MHD_NO; + goto err; } api->dht->lookup.state = OP_EMPTY; prom_gauge_set(lookup_state, api->dht->lookup.state, NULL); } else { - pthread_mutex_unlock(&api->dht->mutex); - return MHD_NO; + goto err; } ret = queue_lookup_response(api, connection, &response, true); goto end; +err: + pthread_mutex_unlock(&api->dht->mutex); + return MHD_NO; } } |
