当前位置: 首页>>代码示例>>C++>>正文


C++ Dispatcher::run方法代码示例

本文整理汇总了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();
}
开发者ID:xd1313113,项目名称:CS258_CG,代码行数:20,代码来源:CMDRead.cpp

示例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;
}
开发者ID:akalingking,项目名称:papryka,代码行数:21,代码来源:synthetic.cpp

示例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;
}
开发者ID:bcoca,项目名称:multi-daemon,代码行数:101,代码来源:echo.c

示例4: doMain

int doMain(int argc, char* argv[])
{
    Dispatcher disp;
    return disp.run(argc, argv);
}
开发者ID:walb-linux,项目名称:walb-tools,代码行数:5,代码来源:wdevc.cpp


注:本文中的Dispatcher::run方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。