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


C++ SnifferConfiguration::set_timeout方法代码示例

本文整理汇总了C++中SnifferConfiguration::set_timeout方法的典型用法代码示例。如果您正苦于以下问题:C++ SnifferConfiguration::set_timeout方法的具体用法?C++ SnifferConfiguration::set_timeout怎么用?C++ SnifferConfiguration::set_timeout使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在SnifferConfiguration的用法示例。


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

示例1: timeout_elapsed

	PDU& PacketSenderGeneric::send_recv(PDU& spdu, SharedSender& shared_sender, const NetworkInterface& iface, bool promisc, double* rdelay, double* edelay)
	{	
		//wait for previous packet to receive response (TODO: not ideal, plan future change)
		while (sent_pdu) {
			std::this_thread::sleep_for(std::chrono::milliseconds(1000));
		}
		sent_pdu = spdu.clone();

		//start sniff task
		SnifferConfiguration config;
		config.set_promisc_mode(promisc);
		config.set_snap_len(65535);
		config.set_timeout(10);

		//Critical section
		SHARED_SNIFFER_MUTEX.lock();
		Sniffer sniffer{ iface.name(), config };
		SHARED_SNIFFER_MUTEX.unlock();

		bool compute_delay = true;
		if (!rdelay)
			compute_delay = false;
		std::future<void> fresp(std::async(std::launch::async, &PacketSenderGeneric::sniff_task, this, &sniffer, compute_delay));

		//send packet
		std::clock_t effective_sent_time = std::clock();
		std::cout << "Registering packet to send !" << std::endl;
		shared_sender.register_packet(sent_pdu, NetworkInterface(iface));

		//std::cout << "waiting for max " << timeout << "..." << std::endl;
		std::future_status status = fresp.wait_for(std::chrono::seconds(timeout));

		//raise exception in case of timeout
		if (status == std::future_status::timeout)
		{
			sniffer.stop_sniff();
			sent_pdu = NULL;
			throw timeout_elapsed();
		}
		else if (status == std::future_status::deferred)
			std::cout << "DEBUG: packet sniffing deffered... shouldn't happen";

		//Treat response packet
		if (edelay)
			*edelay = ((std::clock() - effective_sent_time) / (double)CLOCKS_PER_SEC) * 1000;
		if (rdelay) {
			*rdelay = response_delay;
		}

		PDU& response(*this->response_pdu);

		//Clean
		sent_pdu = NULL;
		response_delay = NULL;
		//response_pdu = NULL;

		return response;
	}
开发者ID:sgtdede,项目名称:libtins,代码行数:58,代码来源:packet_sender_generic.cpp


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