+
+static int dpdk_read_with_timeout(pcap_t *p, uint16_t portid, uint16_t queueid,struct rte_mbuf **pkts_burst, const uint16_t burst_cnt){
+ struct pcap_dpdk *pd = (struct pcap_dpdk*)(p->priv);
+ int nb_rx = 0;
+ int timeout_ms = p->opt.timeout;
+ int sleep_ms = 0;
+ if (pd->nonblock){
+ // In non-blocking mode, just read once, no mater how many packets are captured.
+ nb_rx = (int)rte_eth_rx_burst(pd->portid, 0, pkts_burst, burst_cnt);
+ }else{
+ // In blocking mode, read many times until packets are captured or timeout or break_loop is setted.
+ // if timeout_ms == 0, it may be blocked forever.
+ while (timeout_ms == 0 || sleep_ms < timeout_ms){
+ nb_rx = (int)rte_eth_rx_burst(pd->portid, 0, pkts_burst, burst_cnt);
+ if (nb_rx){ // got packets within timeout_ms
+ break;
+ }else{ // no packet arrives at this round.
+ if (p->break_loop){
+ break;
+ }
+ // sleep for a very short while, but do not block CPU.
+ rte_delay_us_block(DPDK_DEF_MIN_SLEEP_MS*1000);
+ sleep_ms += DPDK_DEF_MIN_SLEEP_MS;
+ }
+ }
+ }
+ return nb_rx;
+}
+