本文整理汇总了C++中io_service::run方法的典型用法代码示例。如果您正苦于以下问题:C++ io_service::run方法的具体用法?C++ io_service::run怎么用?C++ io_service::run使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类io_service
的用法示例。
在下文中一共展示了io_service::run方法的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: start
void ctx_impl::start(size_t worker_pool_size) {
if (running) return;
running = true;
LOG(INFO) << "Starting distributed policy engine";
work.reset(new io_service::work(io));
for (size_t i = 0; i < worker_pool_size; i++) {
workers.emplace_back([this]() {
while (this->running) {
try {
io.run();
} catch (const std::exception& e) {
LOG(ERROR) << "Exception while processing I/O: "
<< e.what();
} catch (...) {
LOG(ERROR) << "Unknown error while processing I/O";
}
}
});
}
rpc.set_seeds(seeds);
rpc.start();
// leveldb::Options options;
// options.create_if_missing = true;
// leveldb::DB* dbPtr = nullptr;
// path systemDbPath = dbPath;
// systemDbPath /= "__system__";
// leveldb::Status status = leveldb::DB::Open(options,
// systemDbPath.string(),
// &dbPtr);
// if (!status.ok()) {
// throw std::runtime_error(string("Could not create/open database: ") +
// status.ToString());
// } else {
// systemDb.reset(dbPtr);
// dbPtr = nullptr;
// }
}
示例2: main
int main(int argc, char const *argv[])
{
parse_args(argc, argv);
if (num < 1 || num > 10000000)
{
std::cerr << "Bad value for 'num': " << num << std::endl;
usage();
}
if (interval < 1 || interval > 100000)
{
std::cerr << "Bad value for 'interval': " << interval << std::endl;
}
if (counters < 1 || counters > 10000)
{
std::cerr << "Bad value for 'counters': " << counters << std::endl;
}
totalCount_ = 0;
calculate_counters();
connect_socket();
// run, waiting for clean shutdown signals, single-threaded
struct sigaction sact;
memset(&sact, 0, sizeof(sact));
sact.sa_handler = stop_running;
sigaction(SIGINT, &sact, 0);
sigaction(SIGHUP, &sact, 0);
start_timer(0);
struct timeval tv1, tv2;
gettimeofday(&tv1, NULL);
svc_.run();
gettimeofday(&tv2, NULL);
if (!running_)
{
std::cerr << "Interrupted." << std::endl;
}
double seconds = (tv2.tv_sec - tv1.tv_sec) + (tv2.tv_usec - tv1.tv_usec) * 0.000001;
std::cout << "Sent " << totalCount_ << " metrics in " << seconds << " seconds." << std::endl;
return running_ ? 0 : 1;
}
示例3: main
int main(int argc, char* argv[]) {
if(argc != 2) {
cerr << "Usage: " << argv[0] << " <com port name>" << endl;
return EXIT_FAILURE;
}
EnvSignals reader(argv[1], // port name
115200, // baud rate
serial_port::parity::none, //
8, // data bits
serial_port::stop_bits::one, //
1 // modbus address
);
reader.start();
io.run();
return EXIT_SUCCESS;
}
示例4: main
int main(int argc, char **argv)
{
if (argc > 1)
if (strcmp(argv[1], "-h") == 0 || strcmp(argv[1], "--help") == 0) {
printf("\n Usage: %s [ThreadCount] [Connection_Count] [QueryDataLength]\n", argv[0]);
printf("\n Default: %s %d 1024 4\n", argv[0], thread_count);
printf("\n For example:\n %s 2 1000 32\n", argv[0]);
printf("\n That's means: start client with 2 threads, create 1000 tcp connection to server, and per data-package is 32 bytes.\n\n");
exit(1);
}
if (argc > 1)
thread_count = atoi(argv[1]);
if (argc > 2)
conn_count = atoi(argv[2]);
if (argc > 3)
qdata = atoi(argv[3]);
rlimit of = {65536, 65536};
if (-1 == setrlimit(RLIMIT_NOFILE, &of)) {
perror("setrlimit");
exit(1);
}
for (int i = 0; i < conn_count; ++i)
echo_client();
boost::thread_group tg;
for (int i = 0; i < thread_count; ++i)
tg.create_thread([]{ ios.run(); });
for (;;) {
#ifdef _WIN32
Sleep(1000);
#else
sleep(1);
#endif
show_status();
}
return 0;
}
示例5: main
int main(int argc, char* argv[]) {
if(argc != 2) {
cerr << "Usage: " << argv[0] << " <com port name>" << endl;
return EXIT_FAILURE;
}
boost::asio::signal_set signals(io, SIGINT, SIGTERM);
signals.async_wait(handler);
EnvSignals reader(argv[1], // port name
9600, // baud rate
serial_port::parity::none, //
8, // data bits
serial_port::stop_bits::one, //
1 // modbus address
);
reader.start();
io.run();
return EXIT_SUCCESS;
}
示例6: run_test
void run_test(std::string const& url, int size, int status, int connected
, boost::optional<error_code> ec, proxy_settings const& ps)
{
reset_globals();
std::cerr << " ===== TESTING: " << url << " =====" << std::endl;
boost::shared_ptr<http_connection> h(new http_connection(ios, cq
, &::http_handler, true, &::http_connect_handler));
h->get(url, seconds(1), 0, &ps);
ios.reset();
ios.run();
std::cerr << "connect_handler_called: " << connect_handler_called << std::endl;
std::cerr << "handler_called: " << handler_called << std::endl;
std::cerr << "status: " << http_status << std::endl;
std::cerr << "size: " << data_size << std::endl;
std::cerr << "error_code: " << g_error_code.message() << std::endl;
TEST_CHECK(connect_handler_called == connected);
TEST_CHECK(handler_called == 1);
TEST_CHECK(data_size == size || size == -1);
TEST_CHECK(!ec || g_error_code == *ec);
TEST_CHECK(http_status == status || status == -1);
}
示例7: worker_thread
void worker_thread() {
service.run();
}
示例8: main
int main()
{
tcp::resolver::query q{"theboostcpplibraries.com", "80"};
resolv.async_resolve(q, resolve_handler);
ioservice.run();
}
示例9: main
int main(int argc, char* argv[]) {
ip::tcp::endpoint ep_c( ip::address::from_string("127.0.0.1"), 8001);
ip::tcp::endpoint ep_s( ip::address::from_string("127.0.0.1"), 8002);
proxy::start(ep_c, ep_s);
service.run();
}
示例10: main
int main(int argc, char **argv)
{
using namespace boost::program_options;
unsigned int reload_period;
options_description desc("General");
bool download_only;
desc.add_options()
("verbose", "Increase console log verbosity")
("quiet", "Only report warnings to console")
("manifest_reload_period", value(&reload_period)->default_value(3), "How ofter to recheck manifest file")
("keep_segments", value(&keep_segments)->default_value(50), "Maximum number of segments in the manifest")
("required_manifest_size", value(&required_manifest_size)->default_value(6), "Number of segments to download before starting ffmpeg")
("ffmpeg_command", value<std::string>(), "Command line to start when enough segments are available")
("log_file", value<std::string>()->default_value("hls_proxy.log"), "Log file name")
("download_only", value(&download_only)->default_value(false), "Just download all the segments mentioned in the manifest")
;
try {
options_description hidden;
hidden.add_options()
("source", value<std::string>()->required(), "HLS source URL")
;
options_description all;
all.add(desc).add(hidden);
variables_map vm;
parsed_options parsed = command_line_parser(argc, argv).
options(all).
positional(positional_options_description().add("source", 1)).
run();
store(parsed, vm);
notify(vm);
if (!download_only) {
if (vm.count("ffmpeg_command") == 0) {
FATAL "ffmpeg_command option required when operating in HLS mode";
return 1;
}
ffmpeg_command = vm["ffmpeg_command"].as<std::string>();
}
manifest_reload_period = boost::posix_time::seconds(reload_period);
using namespace boost::log;
auto file_log = add_file_log (
keywords::file_name = vm["log_file"].as<std::string>(),
keywords::format = "[%TimeStamp%]: %Message%",
keywords::auto_flush = true
);
auto console = add_console_log();
if (vm.count("verbose"))
console->set_filter ( trivial::severity >= trivial::debug );
else if (vm.count("quiet"))
console->set_filter ( trivial::severity >= trivial::warning);
else
console->set_filter ( trivial::severity >= trivial::info);
core::get()->add_global_attribute("TimeStamp", attributes::local_clock());
std::string url = vm["source"].as<std::string>();
INFO "Starting " << url;
if (download_only) {
DownloaderManifestReader manifest_reader;
manifest_reader.load_manifest(url);
ios.run();
} else {
HLSManifestReader manifest_reader;
manifest_reader.load_manifest(url);
ios.run();
}
} catch(boost::program_options::error& e) {
std::cout << e.what() << std::endl;
std::cout << "Usage: " << argv[0] << "[options] <hls-url>" << std::endl;
std::cout << desc << std::endl;
} catch (std::exception& e)
{
FATAL "Exception: " << e.what();
}
}
示例11: main
int main(int argc, char ** argv)
{
if(argc == 1)
{
std::cerr<<"Usage: "<<argv[0]<<" filename"<<std::endl;
return 1;
}
const char * script = argv[1];
init_lua();
lua_State * L = get_lua_state();
switch(luaL_loadfile(L, script))
{
case 0: //success
break;
case LUA_ERRFILE:
case LUA_ERRSYNTAX:
case LUA_ERRMEM:
std::cerr<<lua_tostring(L, -1)<<std::endl;
return 1;
default:;
}
// Create and fill arg table
lua_newtable(L);
for(int i = 2; i < argc; i++)
{
lua_pushinteger(L, i - 1);
lua_pushstring(L, argv[i]);
lua_settable(L, -3);
}
lua_setfield(L, LUA_GLOBALSINDEX, "arg");
#ifdef LUAPP_TABLE
lua_newtable(L);
int T = lua_gettop(L);
bind_function(L, T, "test_func", test);
bind_function(L, T, "file_exists", file_exists);
bind_function(L, T, "dir_exists", dir_exists);
/* lua_pushliteral(L, "vars");
lua_newtable(L);
int vars_table = lua_gettop(L);
luapp::init_constants(L, vars_table);
luapp::init_variables(L, vars_table);
lua_settable(L, -3); // Add vars table to core table*/
lua_setglobal(L, "core"); // Add core table to global table
#endif
if(luaL_dofile(L, script) == 1)
{
std::cerr<<lua_tostring(L, -1)<<std::endl;
return 1;
}
try
{
main_io_service.run();
}
catch(const boost::system::system_error & se)
{
std::cerr<<se.what()<<std::endl;
throw;
}
return 0;
}