static int parsenumber(char *s) { if (!isalldigits(s)) { printf("%s\n", lang_req_obj_number); return(-1); } return(atoi(s)); }
uint64_t metric_value::uint64_t_value(std::string name_associated_with_value_for_error_message) { std::string s = value; trim(s); if (!(isalldigits(s))) throw std::invalid_argument ( std::string("metric_value::uint64_t_value() for name = \"") + name_associated_with_value_for_error_message + std::string("\" - not an unsigned integer \"") + s + std::string("\".") ); std::istringstream si(s); uint64_t n; si >> n; return n; }
int main(int argc, char **argv) { int i; char *host, *p; int port; fd_set fdlist; int maxfd = 0; extern void connect_to_server(char *host, int port, int serverindex); if (argc < 2) { fprintf(stderr, "usage: %s {host port ...} ...\n", argv[0]); return(1); } /* There can't be more than argc servers, so this is enough space: */ if ((serverlist = malloc(argc * sizeof(struct server))) == NULL) { fprintf(stderr, "out of memory!\n"); exit(1); } nservers = 0; for (i = 1; i < argc; i++) { if (isalldigits(argv[i])) { if ((port = atoi(argv[i])) <= 0) { fprintf(stderr, "%s: port argument must be a positive integer\n", argv[0]); return(1); } connect_to_server(host, port, nservers++); /* doesn't return if error */ } else { host = argv[i]; } } //and the rest of your program goes here, obviously while (1) { for (i=0; i < nservers; i++){ if(serverlist[i]->lines_pending){ if ((p = read_line_from_server(serverlist[i]))){ send_another_server(p, serverlist[i]->serfd); } } } FD_ZERO(&fdlist); for (i=0; i < nservers; i++){ FD_SET(serverlist[i]->serfd, &fdlist); if (serverlist[i]->serfd > maxfd){ maxfd = serverlist[i]->serfd; } } FD_SET(0, &fdlist); if (select(maxfd + 1, &fdlist, NULL, NULL, NULL) < 0) { perror("select"); exit(1); } for (i=0; i < nservers; i++){ if (FD_ISSET(serverlist[i]->serfd, &fdlist)) { if ((p = read_line_from_server(serverlist[i]))){ send_another_server(p, serverlist[i]->serfd); } } } } return(0); }