fix spurious 'connection is back' messages.
This commit is contained in:
parent
1cf6c3b02b
commit
dd047dee09
1 changed files with 7 additions and 5 deletions
12
echoc.c
12
echoc.c
|
@ -47,9 +47,11 @@ int
|
||||||
main(int argc, char *argv[])
|
main(int argc, char *argv[])
|
||||||
{
|
{
|
||||||
char name[NI_MAXHOST];
|
char name[NI_MAXHOST];
|
||||||
|
char buf[80];
|
||||||
struct sockaddr_storage client;
|
struct sockaddr_storage client;
|
||||||
struct addrinfo hints, *res, *res0;
|
struct addrinfo hints, *res, *res0;
|
||||||
struct timeval tv;
|
struct timeval tv;
|
||||||
|
struct tm *tm;
|
||||||
struct pollfd pfd[1];
|
struct pollfd pfd[1];
|
||||||
socklen_t addrlen;
|
socklen_t addrlen;
|
||||||
int ch;
|
int ch;
|
||||||
|
@ -108,14 +110,13 @@ main(int argc, char *argv[])
|
||||||
if (nfds == -1 && errno != EINTR)
|
if (nfds == -1 && errno != EINTR)
|
||||||
warn("poll error");
|
warn("poll error");
|
||||||
if ((nfds == 0) || (nfds == -1 && errno == EINTR)) {
|
if ((nfds == 0) || (nfds == -1 && errno == EINTR)) {
|
||||||
|
dropped++;
|
||||||
if (dropped == THRESHOLD) {
|
if (dropped == THRESHOLD) {
|
||||||
struct tm *tm = localtime((time_t *)&tv.tv_sec);
|
tm = localtime((time_t *)&tv.tv_sec);
|
||||||
char buf[80];
|
|
||||||
strftime(buf, sizeof(buf), "%F %T", tm);
|
strftime(buf, sizeof(buf), "%F %T", tm);
|
||||||
printf("%s.%06ld: lost connection\n",
|
printf("%s.%06ld: lost connection\n",
|
||||||
buf, tv.tv_usec);
|
buf, tv.tv_usec);
|
||||||
}
|
}
|
||||||
dropped++;
|
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -139,11 +140,12 @@ main(int argc, char *argv[])
|
||||||
}
|
}
|
||||||
gettimeofday(&tv, NULL);
|
gettimeofday(&tv, NULL);
|
||||||
if (dropped >= THRESHOLD) {
|
if (dropped >= THRESHOLD) {
|
||||||
struct tm *tm = localtime((time_t *)&tv.tv_sec);
|
tm = localtime((time_t *)&tv.tv_sec);
|
||||||
char buf[80];
|
|
||||||
strftime(buf, sizeof(buf), "%F %T", tm);
|
strftime(buf, sizeof(buf), "%F %T", tm);
|
||||||
printf("%s.%02ld: connection is back\n",
|
printf("%s.%02ld: connection is back\n",
|
||||||
buf, tv.tv_usec);
|
buf, tv.tv_usec);
|
||||||
|
if (verbose)
|
||||||
|
printf("dropped %d paquets\n", dropped);
|
||||||
dropped = 0;
|
dropped = 0;
|
||||||
}
|
}
|
||||||
last = buffer;
|
last = buffer;
|
||||||
|
|
Loading…
Add table
Reference in a new issue