fix: handle select() errors in try_recv
This commit is contained in:
parent
3136b10395
commit
2ab904f106
1 changed files with 8 additions and 3 deletions
|
|
@ -1,3 +1,4 @@
|
|||
#include <errno.h>
|
||||
#include <sys/select.h>
|
||||
|
||||
#include "ping/ft_ping_flags.h"
|
||||
|
|
@ -34,7 +35,8 @@ deadline_expired(const struct ping_state *state)
|
|||
|
||||
if (0.0 == state->config->deadline)
|
||||
return 0;
|
||||
icmp_get_time(&now);
|
||||
if (0 != icmp_get_time(&now))
|
||||
return 0;
|
||||
elapsed = (double)(now.tv_sec - state->start_time.tv_sec)
|
||||
+ (double)(now.tv_nsec - state->start_time.tv_nsec) / 1e9;
|
||||
return elapsed >= state->config->deadline;
|
||||
|
|
@ -48,7 +50,8 @@ linger_expired(const struct ping_state *state)
|
|||
|
||||
if (0 == state->linger_start.tv_sec && 0 == state->linger_start.tv_nsec)
|
||||
return 0;
|
||||
icmp_get_time(&now);
|
||||
if (0 != icmp_get_time(&now))
|
||||
return 0;
|
||||
elapsed = (double)(now.tv_sec - state->linger_start.tv_sec)
|
||||
+ (double)(now.tv_nsec - state->linger_start.tv_nsec) / 1e9;
|
||||
return elapsed >= state->config->timeout;
|
||||
|
|
@ -93,7 +96,9 @@ try_recv(struct ping_state *state)
|
|||
FD_ZERO(&rfds);
|
||||
FD_SET(fd, &rfds);
|
||||
ret = select(fd + 1, &rfds, NULL, NULL, &tv);
|
||||
if (0 < ret)
|
||||
if (ret < 0 && errno != EINTR)
|
||||
state->stop_flag = 1;
|
||||
else if (0 < ret)
|
||||
icmp_process(state->handle, ping_callback, state, 0);
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue