int main(int argc, char *argv[]) { const char *host = NULL; int port = MPI_QUEUE_DEFAULT_PORT; char addr[LINK_ADDRESS_MAX]; char c; int w, rank; signal(SIGTERM, handle_abort); signal(SIGQUIT, handle_abort); signal(SIGINT, handle_abort); MPI_Init(&argc, &argv); debug_config(argv[0]); while((c = getopt(argc, argv, "d:ho:t:w:v")) != (char) -1) { switch (c) { case 'd': debug_flags_set(optarg); break; case 't': idle_timeout = string_time_parse(optarg); break; case 'o': debug_config_file(optarg); break; case 'v': show_version(argv[0]); return 0; case 'w': w = string_metric_parse(optarg); link_window_set(w, w); break; case 'h': default: show_help(argv[0]); return 1; } } if ((argc - optind) != 2) { show_help(argv[0]); return 1; } host = argv[optind]; port = atoi(argv[optind + 1]); if(!domain_name_cache_lookup(host, addr)) { fprintf(stderr, "couldn't lookup address of host %s\n", host); exit(1); } MPI_Comm_rank(MPI_COMM_WORLD, &rank); if(rank) { return worker_main(); } else { return master_main(host, port, addr); } }
int main(int argc, char *argv[]) { struct link *link, *master; char *subject = 0, *type = 0; time_t stoptime; char line[1024]; signed char c; int portnum = 30000; char *hostname = 0; int timeout = 30; debug_config(argv[0]); static struct option long_options[] = { {"auth", required_argument, 0, 'a'}, {"port", required_argument, 0, 'p'}, {"host", required_argument, 0, 'r'}, {"help", required_argument, 0, 'h'}, {"debug-file", required_argument, 0, 'o'}, {"debug-rotate-max", required_argument, 0, 'O'}, {"debug", required_argument, 0, 'd'}, {0,0,0,0} }; while((c = getopt_long(argc, argv, "a:p:r:d:o:O:", long_options, NULL)) > -1) { switch (c) { case 'p': portnum = atoi(optarg); break; case 'h': show_help(argv[0]); exit(0); break; case 'r': hostname = optarg; break; case 'd': debug_flags_set(optarg); break; case 'o': debug_config_file(optarg); break; case 'O': debug_config_file_size(string_metric_parse(optarg)); break; case 'a': if(!auth_register_byname(optarg)) fatal("couldn't register %s authentication", optarg); break; default: show_use(argv[0]); exit(1); break; } } if(hostname) { char addr[LINK_ADDRESS_MAX]; stoptime = time(0) + timeout; if(!domain_name_cache_lookup(hostname, addr)) fatal("unknown host name: %s", hostname); link = link_connect(addr, portnum, stoptime); if(!link) fatal("couldn't connect to %s:%d: %s", hostname, portnum, strerror(errno)); if(auth_assert(link, &type, &subject, stoptime)) { printf("server thinks I am %s %s\n", type, subject); if(link_readline(link, line, sizeof(line), stoptime)) { printf("got message: %s\n", line); } else { printf("lost connection!\n"); } } else { printf("unable to authenticate.\n"); } link_close(link); } else { stoptime = time(0) + timeout; master = link_serve(portnum); if(!master) fatal("couldn't serve port %d: %s\n", portnum, strerror(errno)); while(time(0) < stoptime) { link = link_accept(master, stoptime); if(!link) continue; if(auth_accept(link, &type, &subject, stoptime)) { time_t t = time(0); link_putfstring(link, "Hello %s:%s, it is now %s", stoptime, type, subject, ctime(&t)); /* ctime ends with newline */ } else { printf("couldn't auth accept\n"); } link_close(link); } } return 0; }