- Timestamp:
- May 1, 2010, 4:37:52 AM (12 years ago)
- Location:
- branches/1.9x/libtransmission
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/1.9x/libtransmission/list.c
r9891 r10583 158 158 return size; 159 159 } 160 161 162 163 /*164 * Double-linked list with easy memory management and fast165 * insert/remove operations166 */167 168 169 void170 __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 void181 __tr_list_splice( struct __tr_list * prev,182 struct __tr_list * next)183 {184 next->prev = prev;185 prev->next = next;186 }187 188 void189 __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 void196 __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 102 102 103 103 104 /** @brief Double-linked list with easy memory management and fast insert/remove operations */105 struct __tr_list106 {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_list113 * @param type struct type that has contains the __tr_list114 * @param field the name of the struct's _tr_list field115 */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 void124 __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 void132 __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 void138 __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 149 104 /* @} */ 150 105 #endif /* TR_LIST_H */ -
branches/1.9x/libtransmission/peer-io.c
r10567 r10583 76 76 tr_bool isPieceData; 77 77 size_t length; 78 struct __tr_list head;79 78 }; 80 79 … … 88 87 while( bytes_transferred && tr_isPeerIo( io ) ) 89 88 { 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 91 91 const size_t payload = MIN( next->length, bytes_transferred ); 92 92 const size_t overhead = guessPacketOverhead( payload ); … … 105 105 next->length -= payload; 106 106 if( !next->length ) { 107 __tr_list_remove( io->outbuf_datatypes.next);107 tr_list_pop_front( &io->outbuf_datatypes ); 108 108 tr_free( next ); 109 109 } … … 399 399 event_set( &io->event_write, io->socket, EV_WRITE, event_write_cb, io ); 400 400 401 __tr_list_init( &io->outbuf_datatypes );402 403 401 return io; 404 402 } … … 449 447 assert( io->session != NULL ); 450 448 assert( io->session->events != NULL ); 449 assert( io->socket >= 0 ); 451 450 assert( event_initialized( &io->event_read ) ); 452 451 assert( event_initialized( &io->event_write ) ); … … 512 511 **** 513 512 ***/ 514 515 static void516 trDatatypeFree( void * data )517 {518 struct tr_datatype * dt = __tr_list_entry( data, struct tr_datatype, head );519 tr_free(dt);520 }521 513 522 514 static void … … 536 528 tr_netClose( io->session, io->socket ); 537 529 tr_cryptoFree( io->crypto ); 538 __tr_list_destroy( &io->outbuf_datatypes, trDatatypeFree );530 tr_list_free( &io->outbuf_datatypes, tr_free ); 539 531 540 532 memset( io, ~0, sizeof( tr_peerIo ) ); … … 801 793 datatype->isPieceData = isPieceData != 0; 802 794 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 ); 806 796 807 797 switch( io->encryptionMode ) … … 982 972 { 983 973 size_t byteCount = 0; 984 struct __tr_list * walk; 985 struct __tr_list * fencepost = &io->outbuf_datatypes; 974 tr_list * it; 986 975 987 976 /* count up how many bytes are used by non-piece-data messages 988 977 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 991 982 if( d->isPieceData ) 992 983 break; 984 993 985 byteCount += d->length; 994 986 } -
branches/1.9x/libtransmission/peer-io.h
r9868 r10583 28 28 #include "transmission.h" 29 29 #include "bandwidth.h" 30 #include "list.h" /* __tr_list */30 #include "list.h" /* tr_list */ 31 31 #include "net.h" /* tr_address */ 32 32 … … 107 107 struct evbuffer * inbuf; 108 108 struct evbuffer * outbuf; 109 struct __tr_listoutbuf_datatypes; /* struct tr_datatype */109 struct tr_list * outbuf_datatypes; /* struct tr_datatype */ 110 110 111 111 struct event event_read;
Note: See TracChangeset
for help on using the changeset viewer.