| 428 |
|
extern int optind; |
| 429 |
|
int c; |
| 430 |
|
|
| 431 |
+ |
time_t last_update = 0; |
| 432 |
+ |
|
| 433 |
|
WINDOW *window; |
| 434 |
|
|
| 433 |
– |
int stdin_fileno; |
| 434 |
– |
fd_set infds; |
| 435 |
– |
struct timeval timeout; |
| 436 |
– |
|
| 435 |
|
extern int errno; |
| 438 |
– |
char ch; |
| 436 |
|
|
| 437 |
|
int delay=2; |
| 438 |
|
#ifdef ALLBSD |
| 446 |
|
} |
| 447 |
|
#endif |
| 448 |
|
|
| 449 |
< |
while ((c = getopt(argc, argv, "vhd:")) != EOF){ |
| 449 |
> |
while ((c = getopt(argc, argv, "vhd:")) != -1){ |
| 450 |
|
switch (c){ |
| 451 |
|
case 'd': |
| 452 |
|
delay = atoi(optarg); |
| 473 |
|
nonl(); |
| 474 |
|
cbreak(); |
| 475 |
|
noecho(); |
| 476 |
+ |
timeout(delay * 1000); |
| 477 |
|
window=newwin(0, 0, 0, 0); |
| 478 |
|
clear(); |
| 479 |
|
|
| 484 |
|
} |
| 485 |
|
|
| 486 |
|
display_headings(); |
| 489 |
– |
stdin_fileno=fileno(stdin); |
| 487 |
|
|
| 488 |
|
for(;;){ |
| 489 |
+ |
time_t now; |
| 490 |
+ |
int ch = getch(); |
| 491 |
|
|
| 492 |
< |
FD_ZERO(&infds); |
| 493 |
< |
FD_SET(stdin_fileno, &infds); |
| 494 |
< |
timeout.tv_sec = delay; |
| 496 |
< |
timeout.tv_usec = 0; |
| 497 |
< |
|
| 498 |
< |
if((select((stdin_fileno+1), &infds, NULL, NULL, &timeout)) == -1){ |
| 499 |
< |
if(errno!=EINTR){ |
| 500 |
< |
perror("select failed"); |
| 501 |
< |
exit(1); |
| 502 |
< |
} |
| 492 |
> |
if (ch == 'q'){ |
| 493 |
> |
endwin(); |
| 494 |
> |
return 0; |
| 495 |
|
} |
| 496 |
|
|
| 497 |
< |
if(FD_ISSET(stdin_fileno, &infds)){ |
| 498 |
< |
ch=getch(); |
| 499 |
< |
if (ch == 'q'){ |
| 500 |
< |
endwin(); |
| 501 |
< |
return 0; |
| 502 |
< |
} |
| 497 |
> |
/* To keep the numbers slightly accurate we do not want them |
| 498 |
> |
* updating more frequently than once a second. |
| 499 |
> |
*/ |
| 500 |
> |
now = time(NULL); |
| 501 |
> |
if ((now - last_update) >= 1) { |
| 502 |
> |
get_stats(); |
| 503 |
|
} |
| 504 |
+ |
last_update = now; |
| 505 |
|
|
| 513 |
– |
get_stats(); |
| 514 |
– |
|
| 506 |
|
display_data(); |
| 516 |
– |
|
| 517 |
– |
/* To keep the numbers slightly accurate we do not want them updating more |
| 518 |
– |
* frequently than once a second. |
| 519 |
– |
*/ |
| 520 |
– |
sleep(1); |
| 507 |
|
} |
| 508 |
|
|
| 509 |
|
endwin(); |