int main(int argc, char *argv[]) { bool return_status = 0; parameters params; return_status += parse_cli_opts(argc, argv, params); std::vector<ball> b; if (1 == params.type) { type_1_init(params, b); simulate_1(params, b); } else if (2 == params.type) { type_2_init(params, b); simulate_2(params, b); } else if (3 == params.type) { type_3_init(params, b); simulate_3(params, b); } else if (4 == params.type) { // (sic!) - type 2 init, type 3 sim type_2_init(params, b); simulate_3(params, b); } return return_status; }
int main (int argc, char * argv[]) { int i, status, lsockfd, csockfd; /* local/connection socket file descriptor */ struct sockaddr_in raddr; /* remote address object */ socklen_t raddr_len = sizeof (struct sockaddr_in); pthread_t connThread; /* thread identifier */ User_Settings * o_stngs; /* user suplied settings struct (stores user settings)*/ /* set global variables */ server = "simpleText"; version = 1.0f; /* allocate user suplied settings struct */ o_stngs = malloc(sizeof(User_Settings)); /* read configuration file */ read_conf_file (o_stngs); /* parse and set cli options */ parse_cli_opts (argc, (char **) &argv[0], o_stngs); /* make daemon and start logging */ status = init_daemon (server, o_stngs); if (status == 0) return EXIT_SUCCESS; /* parent returns success */ else if (status == 1) return EXIT_FAILURE; /* parent returns failure */ syslog (LOG_NOTICE, "[PID: %u, SID: %u] > %s started..", getpid (), getsid (getpid ()), server); /* Read Hosts File */ host_cnt = read_host_file (NULL, 1); for (i = 0; i < host_cnt; i++) read_host_file (&o_vhost[i], 0); /* start listening for TCP connections */ lsockfd = start_listen (o_stngs->port); free(o_stngs); /* loop through accepting and handling connections */ while (1) { /* accept connection or skip to next conection if accept fails */ csockfd = accept (lsockfd, (struct sockaddr *) &raddr, &raddr_len); if (csockfd == -1) /* if connection fails ignore it and continue */ continue; Connect_Args * o_args = malloc(sizeof(Connect_Args *)); o_args->socket = csockfd; strcpy (o_args->client_addr, inet_ntoa (raddr.sin_addr)); /* create thread to handle connection */ pthread_create(&connThread, NULL, (void *) &attent_connection, o_args); /* wait for one second before accepting next connection */ sleep (1); } }