int main(int argc, char** argv){ Server* s; try { boost::asio::io_service io_service_server; unsigned port; if (argc < 2) port=1234; else port=std::atoi(argv[1]); tcp::endpoint endpoint(tcp::v4(), port); s = new Server(io_service_server, endpoint); boost::thread server_t(boost::bind(&boost::asio::io_service::run, &io_service_server)); Worker w; while(true){ Message msg = s->receive(); s->send(msg.source(),"challenge accepted"); // std::cout << msg.getString(); s->send(msg.source(),w.execute(msg.body())); } server_t.join(); } catch (std::exception& e) { std::cerr << "Exception: " << e.what() << "\n"; } return 0; }
/* Parse the args */ void parse(config_t *config, int argc, char *argv[]) { optind = 1; // reinit getopt while(1) { int do_help = 0; struct option long_options[] = { {"server", required_argument, 0, 's'}, {"clients", required_argument, 0, 'c'}, {"workload", required_argument, 0, 'w'}, {"keys", required_argument, 0, 'k'}, {"keys-prefix", required_argument, 0, 'K'}, {"values", required_argument, 0, 'v'}, {"duration", required_argument, 0, 'd'}, {"batch-factor", required_argument, 0, 'b'}, {"range-size", required_argument, 0, 'R'}, {"latency-file", required_argument, 0, 'l'}, {"worst-latency-file", required_argument, 0, 'L'}, {"qps-file", required_argument, 0, 'q'}, {"out-file", required_argument, 0, 'o'}, {"in-file", required_argument, 0, 'i'}, {"db-file", required_argument, 0, 'f'}, {"distr", required_argument, 0, 'r'}, {"mu", required_argument, 0, 'm'}, {"pipeline", required_argument, 0, 'p'}, {"client-suffix", no_argument, 0, 'a'}, {"ignore-protocol-errors", no_argument, &config->ignore_protocol_errors, 1}, {"help", no_argument, &do_help, 1}, {0, 0, 0, 0} }; int option_index = 0; int c = getopt_long(argc, argv, "s:n:p:r:c:w:k:K:v:d:b:R:l:L:q:o:i:h:f:m:", long_options, &option_index); if(do_help) c = 'h'; /* Detect the end of the options. */ if (c == -1) break; switch (c) { case 0: break; case 's': { server_t server; server.parse(optarg); config->servers.push_back(server); break; } case 'c': config->clients = atoi(optarg); break; case 'w': config->op_ratios.parse(optarg); break; case 'k': config->keys.parse(optarg); break; case 'K': config->key_prefix = optarg; break; case 'v': config->values.parse(optarg); if (config->values.min > MAX_VALUE_SIZE || config->values.max > MAX_VALUE_SIZE) { fprintf(stderr, "Invalid value distribution (maximum value size exceeded).\n"); exit(-1); } break; case 'd': config->duration.parse(optarg); break; case 'b': config->batch_factor.parse(optarg); break; case 'R': config->range_size.parse(optarg); break; case 'l': strncpy(config->latency_file, optarg, MAX_FILE); break; case 'L': strncpy(config->worst_latency_file, optarg, MAX_FILE); break; case 'q': strncpy(config->qps_file, optarg, MAX_FILE); break; case 'o': strncpy(config->out_file, optarg, MAX_FILE); break; case 'i': strncpy(config->in_file, optarg, MAX_FILE); break; case 'f': strncpy(config->db_file, optarg, MAX_FILE); break; case 'a': fprintf(stderr, "Warning: The \"--client-suffix\" (alias \"-a\") flag is deprecated. " "Per-client suffixes are always enabled now.\n"); break; case 'r': if(strcmp(optarg, "uniform") == 0) { config->distr = rnd_uniform_t; } else if(strcmp(optarg, "normal") == 0) { config->distr = rnd_normal_t; } break; case 'm': config->mu = atoi(optarg); break; case 'p': config->pipeline_limit = atoi(optarg); if(config->pipeline_limit < 1) { fprintf(stderr, "Minimum pipeline value is 1.\n"); usage(argv[0]); } // the code is structured in a way where zero means no pipelining, so we subtract one config->pipeline_limit--; break; case 'h': usage(argv[0]); break; default: /* getopt_long already printed an error message. */ usage(argv[0]); } } if (config->servers.size() == 0) { // No server specified -- add one to be used as the default. config->servers.push_back(server_t()); } //validation: bool only_sockmemcached = true; for(int i = 0; i < config->servers.size(); i++) { if(config->servers[i].protocol != protocol_sockmemcached) { only_sockmemcached = false; break; } } if (config->pipeline_limit > 0) { if (config->op_ratios.deletes > 0 || config->op_ratios.updates > 0 || config->op_ratios.inserts > 0 || config->op_ratios.range_reads > 0 || config->op_ratios.appends > 0 || config->op_ratios.prepends > 0 || config->op_ratios.verifies > 0 || !only_sockmemcached) { fprintf(stderr, "Pipelining can only be used with read operations on a sockmemcached protocol.\n"); usage(argv[0]); } } }