Process all packets in ring and dump to capture file */
| 902 | |
| 903 | /* Process all packets in ring and dump to capture file */ |
| 904 | static int process_ring(dumpcap_out_t out, struct rte_ring *r) |
| 905 | { |
| 906 | struct rte_mbuf *pkts[BURST_SIZE]; |
| 907 | unsigned int avail, n; |
| 908 | static unsigned int empty_count; |
| 909 | ssize_t written; |
| 910 | |
| 911 | n = rte_ring_sc_dequeue_burst(r, (void **) pkts, BURST_SIZE, |
| 912 | &avail); |
| 913 | if (n == 0) { |
| 914 | /* don't consume endless amounts of cpu if idle */ |
| 915 | if (empty_count < SLEEP_THRESHOLD) |
| 916 | ++empty_count; |
| 917 | else |
| 918 | usleep(10); |
| 919 | return 0; |
| 920 | } |
| 921 | |
| 922 | empty_count = (avail == 0); |
| 923 | |
| 924 | if (use_pcapng) |
| 925 | written = rte_pcapng_write_packets(out.pcapng, pkts, n); |
| 926 | else |
| 927 | written = pcap_write_packets(out.dumper, pkts, n); |
| 928 | |
| 929 | rte_pktmbuf_free_bulk(pkts, n); |
| 930 | |
| 931 | if (written < 0) |
| 932 | return -1; |
| 933 | |
| 934 | file_size += written; |
| 935 | packets_received += n; |
| 936 | if (!quiet) |
| 937 | show_count(packets_received); |
| 938 | |
| 939 | return 0; |
| 940 | } |
| 941 | |
| 942 | int main(int argc, char **argv) |
| 943 | { |
no test coverage detected