Commit d998ea4b authored by Aurelio Colosimo's avatar Aurelio Colosimo

unix socket handling: fix select timeouts in multilink context

The select must be always called with the least required timeout.
This patch fixes a bug which caused an undesired delay when a state
machine, after receiving a packet, needed to be called soon (e.g.
when it has just changed its status: its desired delay is 0).
Signed-off-by: Aurelio Colosimo's avatarAurelio Colosimo <aurelio@aureliocolosimo.it>
parent 89a46c6d
......@@ -100,6 +100,7 @@ void unix_main_loop(struct pp_globals *ppg)
delay_ms = -1;
for (j = 0; j < ppg->nlinks; j++) {
int tmp_d;
ppi = &ppg->pp_instances[j];
if ((NP(ppi)->ch[PP_NP_GEN].pkt_present) ||
......@@ -121,8 +122,11 @@ void unix_main_loop(struct pp_globals *ppg)
continue;
}
pp_state_machine(ppi, ppi->rx_ptp,
tmp_d = pp_state_machine(ppi, ppi->rx_ptp,
i - NP(ppi)->ptp_offset);
if ((delay_ms == -1) || (tmp_d < delay_ms))
delay_ms = tmp_d;
}
}
}
......
......@@ -103,6 +103,7 @@ void wrs_main_loop(struct pp_globals *ppg)
delay_ms = -1;
for (j = 0; j < ppg->nlinks; j++) {
int tmp_d;
ppi = &ppg->pp_instances[j];
if ((NP(ppi)->ch[PP_NP_GEN].pkt_present) ||
......@@ -124,8 +125,11 @@ void wrs_main_loop(struct pp_globals *ppg)
continue;
}
pp_state_machine(ppi, ppi->rx_ptp,
tmp_d = pp_state_machine(ppi, ppi->rx_ptp,
i - NP(ppi)->ptp_offset);
if ((delay_ms == -1) || (tmp_d < delay_ms))
delay_ms = tmp_d;
}
}
}
......
......@@ -401,8 +401,13 @@ int unix_net_check_pkt(struct pp_globals *ppg, int delay_ms)
int ret = 0;
int maxfd = 0;
struct unix_arch_data *arch_data = POSIX_ARCH(ppg);
int old_delay_ms;
if (delay_ms != -1) {
old_delay_ms = arch_data->tv.tv_sec * 1000 +
arch_data->tv.tv_usec / 1000;
if ((delay_ms != -1) &&
((old_delay_ms == 0) || (delay_ms < old_delay_ms))) {
/* Wait for a packet or for the timeout */
arch_data->tv.tv_sec = delay_ms / 1000;
arch_data->tv.tv_usec = (delay_ms % 1000) * 1000;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment