Changeset 10583


Ignore:
Timestamp:
May 1, 2010, 4:37:52 AM (11 years ago)
Author:
charles
Message:

(1.9x libT) backport r10524 for #2842 "crashes on ARM-based Synology NAS"

Location:
branches/1.9x/libtransmission
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • branches/1.9x/libtransmission/list.c

    r9891 r10583  
    158158    return size;
    159159}
    160 
    161 
    162 
    163 /*
    164  * Double-linked list with easy memory management and fast
    165  * insert/remove operations
    166  */
    167 
    168 
    169 void
    170 __tr_list_insert( struct __tr_list * list,
    171                   struct __tr_list * prev,
    172                   struct __tr_list * next)
    173 {
    174     next->prev = list;
    175     list->next = next;
    176     list->prev = prev;
    177     prev->next = list;
    178 }
    179 
    180 static void
    181 __tr_list_splice( struct __tr_list * prev,
    182                   struct __tr_list * next)
    183 {
    184     next->prev = prev;
    185     prev->next = next;
    186 }
    187 
    188 void
    189 __tr_list_remove( struct __tr_list * head )
    190 {
    191     __tr_list_splice( head->prev, head->next );
    192     head->next = head->prev = NULL;
    193 }
    194 
    195 void
    196 __tr_list_destroy( struct __tr_list * head,
    197                    __tr_list_free_t   func)
    198 {
    199     while ( head->next != head )
    200     {
    201         struct __tr_list * list = head->next;
    202         __tr_list_splice( list->prev, list->next );
    203 
    204         func( list );
    205     }
    206 }
  • branches/1.9x/libtransmission/list.h

    r9891 r10583  
    102102
    103103
    104 /** @brief Double-linked list with easy memory management and fast insert/remove operations */
    105 struct __tr_list
    106 {
    107     struct __tr_list * next, * prev;
    108 };
    109 
    110 /**
    111  * @brief Given a __tr_list node that's embedded in a struct, returns a pointer to the struct.
    112  * @param ptr     pointer to the embedded __tr_list
    113  * @param type    struct type that has contains the __tr_list
    114  * @param field   the name of the struct's _tr_list field
    115  */
    116 #define __tr_list_entry(ptr,type,field) ((type*) (((char*)ptr) - offsetof(type,field)))
    117 
    118 typedef int  ( *__tr_list_cmp_t ) ( const void * a, const void * b );
    119 typedef void ( *__tr_list_free_t )( void * );
    120 
    121 
    122 /** @brief Init @head as an empty list. */
    123 static inline void
    124 __tr_list_init( struct __tr_list * head )
    125 {
    126     head->next = head->prev = head;
    127 }
    128 
    129 
    130 /** @brief Insert @list between @prev and @next. */
    131 void
    132 __tr_list_insert( struct __tr_list * list,
    133                   struct __tr_list * prev,
    134                   struct __tr_list * next);
    135 
    136 /** @brief Append @list to the end of @head. */
    137 static inline void
    138 __tr_list_append( struct __tr_list * head, struct __tr_list * list)
    139 {
    140     __tr_list_insert( list, head->prev, head );
    141 }
    142 
    143 /** @brief Remove @head from the list it is in. */
    144 void __tr_list_remove( struct __tr_list * head );
    145 
    146 /** @brief Destroy the list and free all nodes */
    147 void __tr_list_destroy( struct __tr_list * head, __tr_list_free_t func );
    148 
    149104/* @} */
    150105#endif /* TR_LIST_H */
  • branches/1.9x/libtransmission/peer-io.c

    r10567 r10583  
    7676    tr_bool  isPieceData;
    7777    size_t   length;
    78     struct __tr_list head;
    7978};
    8079
     
    8887     while( bytes_transferred && tr_isPeerIo( io ) )
    8988     {
    90         struct tr_datatype * next = __tr_list_entry( io->outbuf_datatypes.next, struct tr_datatype, head );
     89        struct tr_datatype * next = io->outbuf_datatypes->data;
     90
    9191        const size_t payload = MIN( next->length, bytes_transferred );
    9292        const size_t overhead = guessPacketOverhead( payload );
     
    105105            next->length -= payload;
    106106            if( !next->length ) {
    107                 __tr_list_remove( io->outbuf_datatypes.next );
     107                tr_list_pop_front( &io->outbuf_datatypes );
    108108                tr_free( next );
    109109            }
     
    399399    event_set( &io->event_write, io->socket, EV_WRITE, event_write_cb, io );
    400400
    401     __tr_list_init( &io->outbuf_datatypes );
    402 
    403401    return io;
    404402}
     
    449447    assert( io->session != NULL );
    450448    assert( io->session->events != NULL );
     449    assert( io->socket >= 0 );
    451450    assert( event_initialized( &io->event_read ) );
    452451    assert( event_initialized( &io->event_write ) );
     
    512511****
    513512***/
    514 
    515 static void
    516 trDatatypeFree( void * data )
    517 {
    518     struct tr_datatype * dt = __tr_list_entry( data, struct tr_datatype, head );
    519     tr_free(dt);
    520 }
    521513
    522514static void
     
    536528    tr_netClose( io->session, io->socket );
    537529    tr_cryptoFree( io->crypto );
    538     __tr_list_destroy( &io->outbuf_datatypes, trDatatypeFree );
     530    tr_list_free( &io->outbuf_datatypes, tr_free );
    539531
    540532    memset( io, ~0, sizeof( tr_peerIo ) );
     
    801793    datatype->isPieceData = isPieceData != 0;
    802794    datatype->length = byteCount;
    803 
    804     __tr_list_init( &datatype->head );
    805     __tr_list_append( &io->outbuf_datatypes, &datatype->head );
     795    tr_list_append( &io->outbuf_datatypes, datatype );
    806796
    807797    switch( io->encryptionMode )
     
    982972{
    983973    size_t byteCount = 0;
    984     struct __tr_list * walk;
    985     struct __tr_list * fencepost = &io->outbuf_datatypes;
     974    tr_list * it;
    986975
    987976    /* count up how many bytes are used by non-piece-data messages
    988977       at the front of our outbound queue */
    989     for( walk=fencepost->next; walk!=fencepost; walk=walk->next ) {
    990         struct tr_datatype * d = __tr_list_entry( walk, struct tr_datatype, head );
     978    for( it=io->outbuf_datatypes; it!=NULL; it=it->next )
     979    {
     980        struct tr_datatype * d = it->data;
     981
    991982        if( d->isPieceData )
    992983            break;
     984
    993985        byteCount += d->length;
    994986    }
  • branches/1.9x/libtransmission/peer-io.h

    r9868 r10583  
    2828#include "transmission.h"
    2929#include "bandwidth.h"
    30 #include "list.h" /* __tr_list */
     30#include "list.h" /* tr_list */
    3131#include "net.h" /* tr_address */
    3232
     
    107107    struct evbuffer     * inbuf;
    108108    struct evbuffer     * outbuf;
    109     struct __tr_list      outbuf_datatypes; /* struct tr_datatype */
     109    struct tr_list      * outbuf_datatypes; /* struct tr_datatype */
    110110
    111111    struct event          event_read;
Note: See TracChangeset for help on using the changeset viewer.