Changeset 754


Ignore:
Timestamp:
04/27/06 11:36:36 (7 years ago)
Author:
spa1
Message:

Fixed error where the packet's sequence number was corrupted whenever the
rt_read buffer was being refilled.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/lib/format_rt.c

    r743 r754  
    8282        char *pkt_buffer; 
    8383        char *buf_current; 
    84         int buf_left; 
     84        int buf_filled; 
    8585 
    8686         
     
    197197        RT_INFO->pkt_buffer = NULL; 
    198198        RT_INFO->buf_current = NULL; 
    199         RT_INFO->buf_left = 0; 
     199        RT_INFO->buf_filled = 0; 
    200200         
    201201        if (strlen(uridata) == 0) { 
     
    269269static int rt_read(struct libtrace_t *libtrace, void **buffer, size_t len, int block) { 
    270270        int numbytes; 
    271  
     271        rt_header_t *test_hdr; 
     272         
    272273        assert(len <= RT_BUF_SIZE); 
    273274         
     
    275276                RT_INFO->pkt_buffer = malloc(RT_BUF_SIZE); 
    276277                RT_INFO->buf_current = RT_INFO->pkt_buffer; 
    277                 RT_INFO->buf_left = 0; 
     278                RT_INFO->buf_filled = 0; 
    278279        } 
    279280 
     
    288289 
    289290         
    290         if (len > RT_INFO->buf_left) { 
     291        if (len > RT_INFO->buf_filled) { 
    291292                memcpy(RT_INFO->pkt_buffer, RT_INFO->buf_current,  
    292                                 RT_INFO->buf_left); 
     293                                RT_INFO->buf_filled); 
    293294                RT_INFO->buf_current = RT_INFO->pkt_buffer; 
    294  
     295                 
    295296#ifndef MSG_NOSIGNAL 
    296297#  define MSG_NOSIGNAL 0 
    297298#endif 
    298                 while (len > RT_INFO->buf_left) { 
     299                while (len > RT_INFO->buf_filled) { 
    299300                        if ((numbytes = recv(RT_INFO->input_fd, 
    300                                                 RT_INFO->pkt_buffer +  
    301                                                 RT_INFO->buf_left, 
    302                                                 RT_BUF_SIZE-RT_INFO->buf_left, 
     301                                                RT_INFO->buf_current +  
     302                                                RT_INFO->buf_filled, 
     303                                                RT_BUF_SIZE-RT_INFO->buf_filled, 
    303304                                                MSG_NOSIGNAL|block)) <= 0) { 
    304305                                if (numbytes == 0) { 
     
    335336                        printf("\n"); 
    336337                        */ 
    337                         RT_INFO->buf_left+=numbytes; 
     338                        RT_INFO->buf_filled+=numbytes; 
    338339                } 
    339340 
     
    341342        *buffer = RT_INFO->buf_current; 
    342343        RT_INFO->buf_current += len; 
    343         RT_INFO->buf_left -= len; 
    344         assert(RT_INFO->buf_left >= 0); 
     344        RT_INFO->buf_filled -= len; 
     345        assert(RT_INFO->buf_filled >= 0); 
    345346        return len; 
    346347} 
     
    429430        buf_ptr = ack_buffer; 
    430431 
    431          
    432432        while (to_write > 0) { 
    433433                numbytes = send(RT_INFO->input_fd, buf_ptr, to_write, 0);  
     
    455455                libtrace_packet_t *packet,int blocking) { 
    456456        rt_header_t rt_hdr; 
    457         rt_header_t *pkt_hdr = &rt_hdr; 
     457        static rt_header_t *pkt_hdr = 0; 
    458458        int pkt_size = 0; 
    459          
     459        uint32_t seqno; 
     460         
     461        if (pkt_hdr == 0) 
     462                pkt_hdr = malloc(sizeof(rt_header_t)); 
    460463         
    461464        if (packet->buf_control == TRACE_CTRL_EXTERNAL || !packet->buffer) { 
     
    471474        } 
    472475 
     476        /* Need to salvage these in case the next rt_read overwrites the  
     477         * buffer they came from! */ 
    473478        packet->type = pkt_hdr->type; 
    474479        pkt_size = pkt_hdr->length; 
    475480        packet->size = pkt_hdr->length; 
     481        seqno = pkt_hdr->sequence; 
    476482 
    477483        if (packet->type >= RT_DATA_SIMPLE) { 
     
    486492                } 
    487493                rt_set_payload(packet); 
    488  
    489494                if (RT_INFO->reliable > 0) { 
    490                         if (rt_send_ack(libtrace, pkt_hdr->sequence)  
     495                        if (rt_send_ack(libtrace, seqno)  
    491496                                        == -1) 
    492497                        { 
     
    519524                        default: 
    520525                                printf("Bad rt type for client receipt: %d\n", 
    521                                         pkt_hdr->type); 
     526                                        packet->type); 
    522527                } 
    523528        } 
Note: See TracChangeset for help on using the changeset viewer.