• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

C++ io_service类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了C++中io_service的典型用法代码示例。如果您正苦于以下问题:C++ io_service类的具体用法?C++ io_service怎么用?C++ io_service使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



在下文中一共展示了io_service类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C++代码示例。

示例1: stopModule

void stopModule(io_service & ios)
{
  ios.stop();
}
开发者ID:skifcorp,项目名称:amigo,代码行数:4,代码来源:prot.cpp


示例2: postNewValue

void postNewValue (io_service & ios, newValFunc_t f, Tag & t, const string& nam, const any& val, Variable::Pointer var  )
{
  ios.post( bind(f, std::ref(t), nam, val, var) );
}
开发者ID:skifcorp,项目名称:amigo,代码行数:4,代码来源:prot.cpp


示例3: enum_net_interfaces

	std::vector<ip_interface> enum_net_interfaces(io_service& ios, error_code& ec)
	{
		TORRENT_UNUSED(ios); // this may be unused depending on configuration
		std::vector<ip_interface> ret;
#if defined TORRENT_BUILD_SIMULATOR

		TORRENT_UNUSED(ec);

		std::vector<address> ips = ios.get_ips();

		for (int i = 0; i < int(ips.size()); ++i)
		{
			ip_interface wan;
			wan.interface_address = ips[i];
			wan.netmask = address_v4::from_string("255.255.255.255");
			strcpy(wan.name, "eth0");
			wan.mtu = ios.sim().config().path_mtu(ips[i], ips[i]);
			ret.push_back(wan);
		}

#elif TORRENT_USE_IFADDRS
		int s = socket(AF_INET, SOCK_DGRAM, 0);
		if (s < 0)
		{
			ec = error_code(errno, boost::asio::error::system_category);
			return ret;
		}

		ifaddrs *ifaddr;
		if (getifaddrs(&ifaddr) == -1)
		{
			ec = error_code(errno, boost::asio::error::system_category);
			close(s);
			return ret;
		}

		for (ifaddrs* ifa = ifaddr; ifa; ifa = ifa->ifa_next)
		{
			if (ifa->ifa_addr == 0) continue;
			if ((ifa->ifa_flags & IFF_UP) == 0) continue;

			int family = ifa->ifa_addr->sa_family;
			if (family == AF_INET
#if TORRENT_USE_IPV6
				|| family == AF_INET6
#endif
				)
			{
				ip_interface iface;
				if (iface_from_ifaddrs(ifa, iface))
				{
					ifreq req;
					memset(&req, 0, sizeof(req));
					// -1 to leave a null terminator
					strncpy(req.ifr_name, iface.name, IF_NAMESIZE - 1);
					if (ioctl(s, siocgifmtu, &req) < 0)
					{
						continue;
					}
					iface.mtu = req.ifr_mtu;
					ret.push_back(iface);
				}
			}
		}
		close(s);
		freeifaddrs(ifaddr);
// MacOS X, BSD and solaris
#elif TORRENT_USE_IFCONF
		int s = socket(AF_INET, SOCK_DGRAM, 0);
		if (s < 0)
		{
			ec = error_code(errno, boost::asio::error::system_category);
			return ret;
		}
		ifconf ifc;
		// make sure the buffer is aligned to hold ifreq structs
		ifreq buf[40];
		ifc.ifc_len = sizeof(buf);
		ifc.ifc_buf = (char*)buf;
		if (ioctl(s, SIOCGIFCONF, &ifc) < 0)
		{
			ec = error_code(errno, boost::asio::error::system_category);
			close(s);
			return ret;
		}

		char *ifr = (char*)ifc.ifc_req;
		int remaining = ifc.ifc_len;

		while (remaining > 0)
		{
			ifreq const& item = *reinterpret_cast<ifreq*>(ifr);

#ifdef _SIZEOF_ADDR_IFREQ
			int current_size = _SIZEOF_ADDR_IFREQ(item);
#elif defined TORRENT_BSD
			int current_size = item.ifr_addr.sa_len + IFNAMSIZ;
#else
			int current_size = sizeof(ifreq);
#endif
//.........这里部分代码省略.........
开发者ID:tchen0123,项目名称:libtorrent,代码行数:101,代码来源:enum_net.cpp


示例4: enum_routes

	std::vector<ip_route> enum_routes(io_service& ios, error_code& ec)
	{
		std::vector<ip_route> ret;
		TORRENT_UNUSED(ios);

#ifdef TORRENT_BUILD_SIMULATOR

		TORRENT_UNUSED(ec);

		std::vector<address> ips = ios.get_ips();

		for (int i = 0; i < int(ips.size()); ++i)
		{
			ip_route r;
			if (ips[i].is_v4())
			{
				r.destination = address_v4();
				r.netmask = address_v4::from_string("255.255.255.0");
				address_v4::bytes_type b = ips[i].to_v4().to_bytes();
				b[3] = 1;
				r.gateway = address_v4(b);
			}
			else
			{
				r.destination = address_v6();
				r.netmask = address_v6::from_string("FFFF:FFFF:FFFF:FFFF::0");
				address_v6::bytes_type b = ips[i].to_v6().to_bytes();
				b[14] = 1;
				r.gateway = address_v6(b);
			}
			strcpy(r.name, "eth0");
			r.mtu = ios.sim().config().path_mtu(ips[i], ips[i]);
			ret.push_back(r);
		}

#elif TORRENT_USE_SYSCTL
/*
		struct rt_msg
		{
			rt_msghdr m_rtm;
			char buf[512];
		};

		rt_msg m;
		int len = sizeof(rt_msg);
		bzero(&m, len);
		m.m_rtm.rtm_type = RTM_GET;
		m.m_rtm.rtm_flags = RTF_UP | RTF_GATEWAY;
		m.m_rtm.rtm_version = RTM_VERSION;
		m.m_rtm.rtm_addrs = RTA_DST | RTA_GATEWAY | RTA_NETMASK;
		m.m_rtm.rtm_seq = 0;
		m.m_rtm.rtm_msglen = len;

		int s = socket(PF_ROUTE, SOCK_RAW, AF_UNSPEC);
		if (s == -1)
		{
			ec = error_code(errno, boost::asio::error::system_category);
			return std::vector<ip_route>();
		}

		int n = write(s, &m, len);
		if (n == -1)
		{
			ec = error_code(errno, boost::asio::error::system_category);
			close(s);
			return std::vector<ip_route>();
		}
		else if (n != len)
		{
			ec = boost::asio::error::operation_not_supported;
			close(s);
			return std::vector<ip_route>();
		}
		bzero(&m, len);

		n = read(s, &m, len);
		if (n == -1)
		{
			ec = error_code(errno, boost::asio::error::system_category);
			close(s);
			return std::vector<ip_route>();
		}

		for (rt_msghdr* ptr = &m.m_rtm; (char*)ptr < ((char*)&m.m_rtm) + n; ptr = (rt_msghdr*)(((char*)ptr) + ptr->rtm_msglen))
		{
			std::cout << " rtm_msglen: " << ptr->rtm_msglen << std::endl;
			std::cout << " rtm_type: " << ptr->rtm_type << std::endl;
			if (ptr->rtm_errno)
			{
				ec = error_code(ptr->rtm_errno, boost::asio::error::system_category);
				return std::vector<ip_route>();
			}
			if (m.m_rtm.rtm_flags & RTF_UP == 0
				|| m.m_rtm.rtm_flags & RTF_GATEWAY == 0)
			{
				ec = boost::asio::error::operation_not_supported;
				return address_v4::any();
			}
			if (ptr->rtm_addrs & RTA_DST == 0
				|| ptr->rtm_addrs & RTA_GATEWAY == 0
//.........这里部分代码省略.........
开发者ID:tchen0123,项目名称:libtorrent,代码行数:101,代码来源:enum_net.cpp


示例5: 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;
}
开发者ID:Gleuwuzah,项目名称:server-v4,代码行数:74,代码来源:luapp.cpp


示例6: worker_thread

void worker_thread() {
	service.run();
}
开发者ID:wfxr,项目名称:CppLab,代码行数:3,代码来源:main.cpp


示例7: stopBTTrackers

void stopBTTrackers()
{
    g_IOService.stop();
    g_Thread.join();
}
开发者ID:minim1ner,项目名称:motocoin-bot,代码行数:5,代码来源:bttrackers.cpp


示例8: 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();
}
开发者ID:feng1o,项目名称:boost-asio,代码行数:6,代码来源:proxy.cpp


示例9: main

int main()
{
    tcp::resolver::query q{"theboostcpplibraries.com", "80"};
    resolv.async_resolve(q, resolve_handler);
    ioservice.run();
}
开发者ID:stormogulen,项目名称:misc-code-snippets,代码行数:6,代码来源:web_client.cpp


示例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();
    }
}
开发者ID:tea,项目名称:hls_proxy,代码行数:76,代码来源:hls_proxy.cpp


示例11: do_sendto

///sendto 发送信息到目的用户端
void talk_to_svr::do_sendto(const std::string &username, const std::string &msg)
{
    //username 和 msg 赋值
    std::string writeMsg("send to " + username + " " + msg + "\n");
    service.post(MEM_FN1(do_write, writeMsg));
}
开发者ID:coderdeng,项目名称:net_code,代码行数:7,代码来源:asyncClient.cpp


示例12: do_ask_clients

///ask for clients 亲求客户端信息
void talk_to_svr::do_ask_clients()
{
    service.post(MEM_FN1(do_write, "ask for clients\n"));
}
开发者ID:coderdeng,项目名称:net_code,代码行数:5,代码来源:asyncClient.cpp


示例13: do_ping

///ping,发送ping请求给服务器
void talk_to_svr::do_ping()
{
    service.post(MEM_FN1(do_write, "ping\n"));
}
开发者ID:coderdeng,项目名称:net_code,代码行数:5,代码来源:asyncClient.cpp


示例14: SetUp

		void SetUp() {
			_ios.reset();
		}
开发者ID:bindung,项目名称:utils,代码行数:3,代码来源:httpserver.cpp


示例15: Poll

	void Poll()
	{
		_io.poll();
	}
开发者ID:erio-nk,项目名称:MyCxxProgram2011,代码行数:4,代码来源:Server.cpp



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
C++ ioport_list类代码示例发布时间:2022-05-31
下一篇:
C++ io_manager类代码示例发布时间:2022-05-31
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap