Changeset 63af502


Ignore:
Timestamp:
09/05/14 16:17:32 (6 years ago)
Author:
Shane Alcock <salcock@…>
Branches:
4.0.1-hotfixes, cachetimestamps, develop, dpdk-ndag, etsilive, libtrace4, master, ndag_format, pfring, rc-4.0.1, rc-4.0.2, rc-4.0.3, rc-4.0.4, ringdecrementfix, ringperformance, ringtimestampfixes
Children:
cf686e1
Parents:
a7c8f4a
Message:

int: and ring: now respect trace_interrupt

Calling trace_interrupt() will now cause the read_packet functions
for these formats to exit, even if there are no packets available to
read.

Previously, the read_packet call would hang until a packet arrived
and then exit, which essentially meant tools like tracesplit would
hang forever if there were no packets.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • lib/format_linux.c

    rc70f59f r63af502  
    893893        int snaplen;
    894894        uint32_t flags = 0;
     895        fd_set readfds;
     896        struct timeval tout;
     897        int ret;
    895898       
    896899        if (!packet->buffer || packet->buf_control == TRACE_CTRL_EXTERNAL) {
     
    928931        iovec.iov_len = snaplen;
    929932
    930         hdr->wirelen = recvmsg(FORMAT(libtrace->format_data)->fd, &msghdr, MSG_TRUNC);
     933        /* Use select to allow us to time out occasionally to check if someone
     934         * has hit Ctrl-C or otherwise wants us to stop reading and return
     935         * so they can exit their program.
     936         */
     937
     938        while (1) {
     939                tout.tv_sec = 0;
     940                tout.tv_usec = 500000;
     941                FD_ZERO(&readfds);
     942                FD_SET(FORMAT(libtrace->format_data)->fd, &readfds);
     943
     944                ret = select(FORMAT(libtrace->format_data)->fd + 1, &readfds,
     945                                NULL, NULL, &tout);
     946                if (ret < 0 && errno != EINTR) {
     947                        trace_set_err(libtrace, errno, "select");
     948                        return -1;
     949                } else if (ret < 0) {
     950                        continue;
     951                }
     952               
     953                if (FD_ISSET(FORMAT(libtrace->format_data)->fd, &readfds)) {
     954                        /* There's something available for us to read */
     955                        break;
     956                }
     957
     958               
     959                /* If we get here, we timed out -- check if we should halt */
     960                if (libtrace_halt)
     961                        return 0;
     962        }
     963
     964        hdr->wirelen = recvmsg(FORMAT(libtrace->format_data)->fd, &msghdr, MSG_TRUNC);
    931965
    932966        if (hdr->wirelen==~0U) {
     
    10441078        assert((((unsigned long) header) & (pagesize - 1)) == 0);
    10451079
    1046         /* TP_STATUS_USER means that we can use the frame.
    1047          * When a slot does not have this flag set, the frame is not
    1048          * ready for consumption.
    1049          */
    1050         while (!(header->tp_status & TP_STATUS_USER)) {
     1080        while (1) {
    10511081                pollset.fd = FORMAT(libtrace->format_data)->fd;
    10521082                pollset.events = POLLIN;
    10531083                pollset.revents = 0;
    10541084                /* Wait for more data */
    1055                 ret = poll(&pollset, 1, -1);
     1085                ret = poll(&pollset, 1, 500);
    10561086                if (ret < 0) {
    10571087                        if (errno != EINTR)
    10581088                                trace_set_err(libtrace,errno,"poll()");
    10591089                        return -1;
    1060                 }
     1090                } else if (ret == 0) {
     1091                        /* Poll timed out - check if we should exit */
     1092                        if (libtrace_halt)
     1093                                return 0;
     1094                        continue;
     1095                }
     1096
     1097                /* TP_STATUS_USER means that we can use the frame.
     1098                 * When a slot does not have this flag set, the frame is not
     1099                 * ready for consumption.
     1100                 */
     1101                if (header->tp_status & TP_STATUS_USER)
     1102                        break;
    10611103        }
    10621104
Note: See TracChangeset for help on using the changeset viewer.