本文整理汇总了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;
}