int main(int argc, char **argv) { int listenfd, port, ret; struct horse *horses; unsigned int horse_num, pperh; pthread_mutex_t mutex, mfinished, mbank, mcur_run, mhb, mnr; pthread_cond_t cond; pthread_barrier_t barrier; struct service service; if (argc != 3) { usage(argv[0]); exit(EXIT_FAILURE); } // parse port port = atoi(argv[1]); listenfd = init_socket(port); _listen(listenfd, LISTENQ); init_sync(&mutex, &cond, &mfinished, &mbank, &mcur_run, &mhb, &mnr); ret = parse_conf_file(argv[2], &horses, &horse_num, &pperh, &mutex, &cond, &barrier, &service); if (ret) goto clean; if (!pperh || pperh > MAX_RACE_NUM) { fprintf(stderr, "races per hour %u should be more than 0 and less than %d\n", pperh, MAX_RACE_NUM + 1); goto clean; } init_signals(); srand(time(NULL)); init_service(&service, &mfinished, &mbank, &mcur_run, &mhb, &mnr, (unsigned int)(60 * 60 / pperh)); server_work(listenfd, &cond, &service, horses, horse_num); clean: // cleaning clean(&mutex, &cond, &mfinished, &mbank, &mcur_run, &mhb, &mnr, horses, listenfd); return EXIT_SUCCESS; }
int main(int argc, char **argv) { int port, timestep; if(argc != 3) usage(argv[0]); port = atoi(argv[1]); timestep = atoi(argv[2]); if(port <= 0 || timestep <= 0) usage(argv[0]); if(sethandler(SIG_IGN, SIGPIPE)) error_exit("Setting SIGPIPE handler:"); if(sethandler(sigint_handler, SIGINT)) error_exit("Setting SIGINT handler:"); t_sigmask(SIGINT, SIG_BLOCK); server_work((uint16_t)port, timestep); return EXIT_SUCCESS; }