summaryrefslogtreecommitdiffstats
path: root/src/core.c
diff options
context:
space:
mode:
authorOpenGnSys Support Team <soporte-og@soleta.eu>2022-01-21 14:29:32 +0100
committerOpenGnSys Support Team <soporte-og@soleta.eu>2022-01-21 15:18:47 +0100
commit20301007a15deede9995da5e6cab3d18ecccedf8 (patch)
tree57816db0ef654fff8813fcf85d2b9134cc3d08f8 /src/core.c
parentb8b3839bba75a96acc852d83b02434d921b0e065 (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/core.c')
-rw-r--r--src/core.c19
1 files changed, 15 insertions, 4 deletions
diff --git a/src/core.c b/src/core.c
index b15efc9..0ff02d4 100644
--- a/src/core.c
+++ b/src/core.c
@@ -323,10 +323,16 @@ void og_server_accept_cb(struct ev_loop *loop, struct ev_io *io, int events)
struct og_client_wol *cli_wol;
struct og_client *cli;
int client_sd;
+ bool agent;
if (events & EV_ERROR)
return;
+ if (io->fd == socket_agent_rest)
+ agent = true;
+ else
+ agent = false;
+
client_sd = accept(io->fd, (struct sockaddr *)&client_addr, &addrlen);
if (client_sd < 0) {
syslog(LOG_ERR, "cannot accept client connection\n");
@@ -342,6 +348,12 @@ void og_server_accept_cb(struct ev_loop *loop, struct ev_io *io, int events)
if (cli_wol)
og_client_wol_destroy(cli_wol);
+ if (agent) {
+ cli = __og_client_find(&client_addr.sin_addr);
+ if (cli)
+ og_client_release(loop, cli);
+ }
+
cli = (struct og_client *)calloc(1, sizeof(struct og_client));
if (!cli) {
close(client_sd);
@@ -349,7 +361,7 @@ void og_server_accept_cb(struct ev_loop *loop, struct ev_io *io, int events)
}
memcpy(&cli->addr, &client_addr, sizeof(client_addr));
- if (io->fd == socket_agent_rest) {
+ if (agent) {
cli->agent = true;
ev_io_init(&cli->io, og_agent_read_cb, client_sd, EV_READ);
} else {
@@ -358,7 +370,7 @@ void og_server_accept_cb(struct ev_loop *loop, struct ev_io *io, int events)
ev_io_start(loop, &cli->io);
ev_init(&cli->timer, og_client_timer_cb);
- if (io->fd == socket_agent_rest)
+ if (agent)
cli->timer.repeat = OG_AGENT_CLIENT_TIMEOUT;
else
cli->timer.repeat = OG_CLIENT_TIMEOUT;
@@ -366,9 +378,8 @@ void og_server_accept_cb(struct ev_loop *loop, struct ev_io *io, int events)
ev_timer_again(loop, &cli->timer);
og_client_add(cli);
- if (io->fd == socket_agent_rest) {
+ if (agent)
og_agent_send_refresh(cli);
- }
}
int og_socket_server_init(const char *port)