#1043 fix timeout refresh

as described by man(3) ev, to make it work with ev_timer_again()
otherwise timer might not ever expire.
master
OpenGnSys Support Team 2021-11-23 10:59:10 +01:00
parent b6b1040997
commit 64bbc0cf3f
2 changed files with 15 additions and 18 deletions

View File

@ -29,6 +29,7 @@
static void og_client_release(struct ev_loop *loop, struct og_client *cli)
{
list_del(&cli->list);
ev_timer_stop(loop, &cli->timer);
ev_io_stop(loop, &cli->io);
close(cli->io.fd);
free(cli);
@ -147,7 +148,6 @@ static void og_client_read_cb(struct ev_loop *loop, struct ev_io *io, int events
}
return;
close:
ev_timer_stop(loop, &cli->timer);
og_client_release(loop, cli);
}
@ -264,7 +264,6 @@ static void og_agent_read_cb(struct ev_loop *loop, struct ev_io *io, int events)
}
return;
close:
ev_timer_stop(loop, &cli->timer);
og_client_release(loop, cli);
}
@ -302,10 +301,10 @@ static void og_agent_send_refresh(struct og_client *cli)
}
/* Shut down connection if there is no complete message after 10 seconds. */
#define OG_CLIENT_TIMEOUT 10
#define OG_CLIENT_TIMEOUT 10.
/* Agent client operation might take longer, shut down after 30 seconds. */
#define OG_AGENT_CLIENT_TIMEOUT 30
#define OG_AGENT_CLIENT_TIMEOUT 30.
#define OG_TCP_KEEPALIVE_IDLE 60
#define OG_TCP_KEEPALIVE_INTL 30
@ -356,14 +355,13 @@ void og_server_accept_cb(struct ev_loop *loop, struct ev_io *io, int events)
}
ev_io_start(loop, &cli->io);
if (io->fd == socket_agent_rest) {
ev_timer_init(&cli->timer, og_client_timer_cb,
OG_AGENT_CLIENT_TIMEOUT, 0.);
} else {
ev_timer_init(&cli->timer, og_client_timer_cb,
OG_CLIENT_TIMEOUT, 0.);
}
ev_timer_start(loop, &cli->timer);
ev_init(&cli->timer, og_client_timer_cb);
if (io->fd == socket_agent_rest)
cli->timer.repeat = OG_AGENT_CLIENT_TIMEOUT;
else
cli->timer.repeat = OG_CLIENT_TIMEOUT;
ev_timer_again(loop, &cli->timer);
og_client_add(cli);
if (io->fd == socket_agent_rest) {

View File

@ -89,7 +89,7 @@ bool wake_up_broadcast(int sd, struct sockaddr_in *client,
return wake_up_send(sd, client, msg, &addr.sin_addr);
}
#define OG_WOL_CLIENT_TIMEOUT 60
#define OG_WOL_CLIENT_TIMEOUT 60.
static void og_client_wol_timer_cb(struct ev_loop *loop, ev_timer *timer,
int events)
@ -100,8 +100,7 @@ static void og_client_wol_timer_cb(struct ev_loop *loop, ev_timer *timer,
syslog(LOG_ERR, "timeout WakeOnLAN request for client %s\n",
inet_ntoa(cli_wol->addr));
list_del(&cli_wol->list);
free(cli_wol);
og_client_wol_destroy(cli_wol);
}
struct og_client_wol *og_client_wol_create(const struct in_addr *addr)
@ -114,9 +113,9 @@ struct og_client_wol *og_client_wol_create(const struct in_addr *addr)
cli_wol->addr = *addr;
ev_timer_init(&cli_wol->timer, og_client_wol_timer_cb,
OG_WOL_CLIENT_TIMEOUT, 0.);
ev_timer_start(og_loop, &cli_wol->timer);
ev_init(&cli_wol->timer, og_client_wol_timer_cb);
cli_wol->timer.repeat = OG_WOL_CLIENT_TIMEOUT;
ev_timer_again(og_loop, &cli_wol->timer);
return cli_wol;
}