diff options
author | OpenGnSys Support Team <soporte-og@soleta.eu> | 2022-01-21 14:29:32 +0100 |
---|---|---|
committer | OpenGnSys Support Team <soporte-og@soleta.eu> | 2022-01-21 15:18:47 +0100 |
commit | 20301007a15deede9995da5e6cab3d18ecccedf8 (patch) | |
tree | 57816db0ef654fff8813fcf85d2b9134cc3d08f8 /src/rest.c | |
parent | b8b3839bba75a96acc852d83b02434d921b0e065 (diff) |
#915 release existing client on reconnections
Trasient network problems might result in duplicated clients, drop
client object if it already exists before creating a new one.
Diffstat (limited to 'src/rest.c')
-rw-r--r-- | src/rest.c | 24 |
1 files changed, 16 insertions, 8 deletions
@@ -86,9 +86,23 @@ void og_client_add(struct og_client *cli) list_add(&cli->list, &client_list); } -static struct og_client *og_client_find(const char *ip) +struct og_client *__og_client_find(const struct in_addr *addr) { struct og_client *client; + + list_for_each_entry(client, &client_list, list) { + if (!client->agent) + continue; + + if (client->addr.sin_addr.s_addr == addr->s_addr) + return client; + } + + return NULL; +} + +static struct og_client *og_client_find(const char *ip) +{ struct in_addr addr; int res; @@ -98,13 +112,7 @@ static struct og_client *og_client_find(const char *ip) return NULL; } - list_for_each_entry(client, &client_list, list) { - if (client->addr.sin_addr.s_addr == addr.s_addr && client->agent) { - return client; - } - } - - return NULL; + return __og_client_find(&addr); } static const char *og_client_status(const struct og_client *cli) |