Commit f80b4f95 authored by Jean-Claude BAU's avatar Jean-Claude BAU

Fix select() call returning EINVAL

During intensive tests playing with ports up and down, the select() call
returned sometime the error value EINVAL because the given timeout was
negative.
parent 6a7bd674
......@@ -231,7 +231,7 @@ static void start_alarm(timer_t *timerid, unsigned int delay_ms) {
}
static int stop_alarm(timer_t *timerid) {
static unsigned int stop_alarm(timer_t *timerid) {
struct itimerspec its;
struct itimerspec ito;
......@@ -294,6 +294,9 @@ void wrs_main_loop(struct pp_globals *ppg)
/* Time to run the state machine */
stop_alarm(&timerid); /* Clear previous alarm */
delay_ms = run_all_state_machines(ppg);
/* We force to run the state machine at a minimum rate of PP_DEFAULT_NEXT_DELAY_MS */
if (delay_ms>PP_DEFAULT_NEXT_DELAY_MS )
delay_ms=PP_DEFAULT_NEXT_DELAY_MS;
alarmDetected=0;
if ( delay_ms != 0 ) {
/* Start the alarm */
......
......@@ -61,7 +61,7 @@ int l1e_run_state_machine(struct pp_instance *ppi, void *buf, int len) {
if ( basicDS->next_state!=L1SYNC_DISABLED &&
(ppi->extState!=PP_EXSTATE_ACTIVE || ppi->state==PPS_INITIALIZING))
return INT_MAX; /* Return a big delay. fsm will then not use it */
return PP_DEFAULT_NEXT_DELAY_MS; /* Return default delay */
if ( nextState>=MAX_STATE_ACTIONS)
return pp_next_delay_2(ppi,L1E_TIMEOUT_TX_SYNC, L1E_TIMEOUT_RX_SYNC);
......
......@@ -594,7 +594,7 @@ static int unix_net_check_packet(struct pp_globals *ppg, int delay_ms)
old_delay_ms = arch_data->tv.tv_sec * 1000 +
arch_data->tv.tv_usec / 1000;
if ((delay_ms != -1) &&
if ((delay_ms >=0 ) &&
((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;
......@@ -625,12 +625,13 @@ static int unix_net_check_packet(struct pp_globals *ppg, int delay_ms)
i = select(maxfd + 1, &set, NULL, NULL, &arch_data->tv);
if ( i < 0 ) {
if ( errno != EINTR )
exit(__LINE__);
else {
if ( errno==EINVAL || errno==EINTR ) {
arch_data->tv.tv_sec =
arch_data->tv.tv_usec =0;
return -1;
} else {
pp_error("%s: Errno=%d %s\n",__func__, errno, strerror(errno));
exit(errno);
}
}
if (i == 0)
......
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