本文整理汇总了C++中Dispatcher::run方法的典型用法代码示例。如果您正苦于以下问题:C++ Dispatcher::run方法的具体用法?C++ Dispatcher::run怎么用?C++ Dispatcher::run使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Dispatcher
的用法示例。
在下文中一共展示了Dispatcher::run方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: execute
void CMDRead::execute()
{
std::string line;
std::ifstream input(filename.c_str());
if(!input)
{
std::cout << "Could not open the given file, please check and try again" << std::endl;
}
else
{
while(std::getline(input, line))
{
Dispatcher* dispatcher = new Dispatcher(const_cast<char*>(line.c_str()));
dispatcher->run();
}
}
input.close();
}
示例2: main
int main(int argc, char** argv)
{
typedef FeedSynthetic<real_t> feed_t;
datetime_t start = to_datetime("2010-01-01");
datetime_t end = to_datetime("2010-12-31");
std::shared_ptr<feed_t> ptr(new feed_t(start, end, Frequency::Day));
std::vector<feed_t::Data> data = {
{"QQQ", 115, 0.2, 0.1},
{"MSFT", 60, 0.2, 0.1},
{"GOOG", 771, 0.2, 0.1}};
ptr->add_values_from_generator(data);
Dispatcher dispatcher;
dispatcher.add_subject(ptr);
dispatcher.run();
return 0;
}
示例3: echo_entry
//.........这里部分代码省略.........
}
if (!strcmp(config_opts[i].name, "port"))
{
port = atoi(config_opts[i].value);
if (port <= 0 || port >= 65535)
{
fprintf(stderr, "Invalid port specification: %s\n", config_opts[i].value);
return 1;
}
}
else if (!strcmp(config_opts[i].name, "proto"))
{
strncpy(proto, config_opts[i].value, sizeof(proto));
proto[sizeof(proto)-1] = 0;
if (!strcmp(proto, "tcp"))
{
socket_type = SOCK_STREAM;
}
else if (!strcmp(proto, "udp"))
{
socket_type = SOCK_DGRAM;
}
else
{
fprintf(stderr, "Invalid proto specification '%s'. Must be one of: tcp, udp\n", config_opts[i].value);
return 1;
}
}
else if (!strcmp(config_opts[i].name, "worker_model"))
{
if (!strcmp(config_opts[i].value, "single"))
{
worker_model = DISPATCHER_WORKER_MODEL_SINGLE;
}
else if (!strcmp(config_opts[i].value, "postfork"))
{
worker_model = DISPATCHER_WORKER_MODEL_POSTFORK;
}
else if (!strcmp(config_opts[i].value, "prefork"))
{
worker_model = DISPATCHER_WORKER_MODEL_PREFORK;
}
else if (!strcmp(config_opts[i].value, "thread"))
{
worker_model = DISPATCHER_WORKER_MODEL_THREAD;
}
else
{
fprintf(stderr, "Invalid worker_model specification: %s\n", config_opts[i].value);
return 1;
}
}
else if (!strcmp(config_opts[i].name, "num_workers"))
{
num_workers = atoi(config_opts[i].value);
if (num_workers <= 0 || num_workers > 200)
{
fprintf(stderr, "Invalid num_workers specification: %s\n", config_opts[i].value);
return 1;
}
}
else
{
fprintf(stderr, "Unsupported option: %s\n", config_opts[i].name);
return 1;
}
}
Socket *sock = Socket_init(0);
sock->create(sock, AF_INET, socket_type);
if (sock == NULL)
{
fprintf(stderr, "Failed to create socket\n");
return 1;
}
sock->set_flag(sock, O_NONBLOCK);
if (sock->bind(sock, "0.0.0.0", port) < 0)
{
fprintf(stderr, "Bind to socket failed\n");
return 1;
}
if (socket_type == SOCK_STREAM)
{
if (sock->listen(sock, 5) < 0)
{
fprintf(stderr, "Listen on socket failed\n");
return 1;
}
}
Dispatcher * disp = Dispatcher_init(worker_model, num_workers);
disp->add_listener(disp, sock, echo_dispatcher_poll_callback, echo_dispatcher_run_callback, echo_dispatcher_cleanup_callback);
disp->run(disp);
disp->destroy(disp);
sock->destroy(sock);
return 0;
}
示例4: doMain
int doMain(int argc, char* argv[])
{
Dispatcher disp;
return disp.run(argc, argv);
}