#include #include #include #include #include #include #include #include "client.h" int main(int argc, char *argv[]) { options_parse(argc, argv); /* Parse options to get leafname before init functions */ display_init(argc, argv); packet_init(); options_daemonize(); signal_init(); while (1) { struct timeval now, tv; struct timeval expire={0L, 0L}; struct timeval *tvp=NULL; int maxfd=-1; fd_set rfds; fd_set wfds; /* int debugf=1; */ /* printf("xid_sent_latest: %i\n", xid_sent_latest); */ /* printf("xid_recv_latest: %i\n", xid_recv_latest); */ /* printf("xid_hand_latest: %i\n", xid_hand_latest); */ /* printf("xid_stored_first: %i\n", xid_stored_first); */ /* printf("xid_stored_last: %i\n", xid_stored_last); */ /* printf("xid_display_first: %i\n", xid_display_first); */ /* printf("xid_display_last: %i\n", xid_display_last); */ FD_ZERO(&rfds); FD_ZERO(&wfds); /* printf("select:"); */ signal_preselect(&maxfd, &rfds, &expire); packet_preselect(&maxfd, &rfds, &expire); display_preselect(&maxfd, &rfds, &wfds, &expire); again: if (expire.tv_sec) { gettimeofday(&now, NULL); tv.tv_sec=expire.tv_sec-now.tv_sec; tv.tv_usec=expire.tv_usec-now.tv_usec; if (tv.tv_usec<0) { tv.tv_sec--; tv.tv_usec+=1000000; } if (tv.tv_sec<0) { tv.tv_sec=tv.tv_usec=0; } /* if (debugf) */ /* printf(" [timeout %li.%li]", */ /* tv.tv_sec, tv.tv_usec); */ tvp=&tv; } /* if (debugf) { printf("\n"); debugf=0; } */ if (select(maxfd+1, &rfds, &wfds, NULL, tvp)==-1) { if (errno==EINTR) goto again; fprintf(stderr, "select: %s\n", strerror(errno)); exit(1); } signal_postselect(&rfds); packet_postselect(&rfds); display_postselect(&rfds, &wfds); } }