Changeset 11299
- Timestamp:
- Oct 11, 2010, 3:41:27 PM (12 years ago)
- Location:
- trunk/libtransmission
- Files:
-
- 10 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/libtransmission/bitfield.c
r11280 r11299 16 16 #include "transmission.h" 17 17 #include "bitfield.h" 18 #include "bitset.h" 18 19 19 20 tr_bitfield* … … 210 211 return ret; 211 212 } 213 214 /*** 215 **** 216 ***/ 217 218 void 219 tr_bitsetReserve( tr_bitset * b, size_t size ) 220 { 221 if( b->bitfield.bitCount < size ) 222 { 223 tr_bitfield * tmp = tr_bitfieldDup( &b->bitfield ); 224 225 tr_bitfieldDestruct( &b->bitfield ); 226 tr_bitfieldConstruct( &b->bitfield, size ); 227 228 if( ( tmp->bits != NULL ) && ( tmp->byteCount > 0 ) ) 229 memcpy( b->bitfield.bits, tmp->bits, tmp->byteCount ); 230 231 tr_bitfieldFree( tmp ); 232 } 233 } -
trunk/libtransmission/bitset.h
r10020 r11299 42 42 } 43 43 44 static inline void 45 tr_bitsetReserve( tr_bitset * b, size_t size ) 46 { 47 if( b->bitfield.bitCount < size ) 48 { 49 tr_bitfield * tmp = tr_bitfieldDup( &b->bitfield ); 50 51 tr_bitfieldDestruct( &b->bitfield ); 52 tr_bitfieldConstruct( &b->bitfield, size ); 53 54 if( ( tmp->bits != NULL ) && ( tmp->byteCount > 0 ) ) 55 memcpy( b->bitfield.bits, tmp->bits, tmp->byteCount ); 56 57 tr_bitfieldFree( tmp ); 58 } 59 } 44 void tr_bitsetReserve( tr_bitset * b, size_t size ); 60 45 61 46 static inline tr_bool -
trunk/libtransmission/peer-io.c
r10931 r11299 613 613 } 614 614 615 const char* tr_peerIoGetAddrStr( const tr_peerIo * io ) 616 { 617 return tr_isPeerIo( io ) ? tr_peerIoAddrStr( &io->addr, io->port ) : "error"; 618 } 619 615 620 void 616 621 tr_peerIoSetIOFuncs( tr_peerIo * io, … … 821 826 } 822 827 828 void 829 tr_peerIoWriteUint16( tr_peerIo * io, 830 struct evbuffer * outbuf, 831 uint16_t writeme ) 832 { 833 const uint16_t tmp = htons( writeme ); 834 tr_peerIoWriteBytes( io, outbuf, &tmp, sizeof( uint16_t ) ); 835 } 836 837 void 838 tr_peerIoWriteUint32( tr_peerIo * io, 839 struct evbuffer * outbuf, 840 uint32_t writeme ) 841 { 842 const uint32_t tmp = htonl( writeme ); 843 tr_peerIoWriteBytes( io, outbuf, &tmp, sizeof( uint32_t ) ); 844 } 845 823 846 /*** 824 847 **** … … 850 873 assert( 0 ); 851 874 } 875 } 876 877 void 878 tr_peerIoReadUint16( tr_peerIo * io, 879 struct evbuffer * inbuf, 880 uint16_t * setme ) 881 { 882 uint16_t tmp; 883 tr_peerIoReadBytes( io, inbuf, &tmp, sizeof( uint16_t ) ); 884 *setme = ntohs( tmp ); 885 } 886 887 void tr_peerIoReadUint32( tr_peerIo * io, 888 struct evbuffer * inbuf, 889 uint32_t * setme ) 890 { 891 uint32_t tmp; 892 tr_peerIoReadBytes( io, inbuf, &tmp, sizeof( uint32_t ) ); 893 *setme = ntohl( tmp ); 852 894 } 853 895 -
trunk/libtransmission/peer-io.h
r11296 r11299 193 193 tr_port port ); 194 194 195 static inline const char* tr_peerIoGetAddrStr( const tr_peerIo * io ) 196 { 197 return tr_isPeerIo( io ) ? tr_peerIoAddrStr( &io->addr, io->port ) : "error"; 198 } 195 const char* tr_peerIoGetAddrStr( const tr_peerIo * io ); 199 196 200 197 const struct tr_address * tr_peerIoGetAddress( const tr_peerIo * io, … … 301 298 } 302 299 303 static inline void tr_peerIoWriteUint16( tr_peerIo * io, 304 struct evbuffer * outbuf, 305 uint16_t writeme ) 306 { 307 const uint16_t tmp = htons( writeme ); 308 tr_peerIoWriteBytes( io, outbuf, &tmp, sizeof( uint16_t ) ); 309 } 310 311 static inline void tr_peerIoWriteUint32( tr_peerIo * io, 312 struct evbuffer * outbuf, 313 uint32_t writeme ) 314 { 315 const uint32_t tmp = htonl( writeme ); 316 tr_peerIoWriteBytes( io, outbuf, &tmp, sizeof( uint32_t ) ); 317 } 300 void tr_peerIoWriteUint16( tr_peerIo * io, 301 struct evbuffer * outbuf, 302 uint16_t writeme ); 303 304 void tr_peerIoWriteUint32( tr_peerIo * io, 305 struct evbuffer * outbuf, 306 uint32_t writeme ); 318 307 319 308 void tr_peerIoReadBytes( tr_peerIo * io, … … 329 318 } 330 319 331 static inline void tr_peerIoReadUint16( tr_peerIo * io, 332 struct evbuffer * inbuf, 333 uint16_t * setme ) 334 { 335 uint16_t tmp; 336 tr_peerIoReadBytes( io, inbuf, &tmp, sizeof( uint16_t ) ); 337 *setme = ntohs( tmp ); 338 } 339 340 static inline void tr_peerIoReadUint32( tr_peerIo * io, 341 struct evbuffer * inbuf, 342 uint32_t * setme ) 343 { 344 uint32_t tmp; 345 tr_peerIoReadBytes( io, inbuf, &tmp, sizeof( uint32_t ) ); 346 *setme = ntohl( tmp ); 347 } 320 void tr_peerIoReadUint16( tr_peerIo * io, 321 struct evbuffer * inbuf, 322 uint16_t * setme ); 323 324 void tr_peerIoReadUint32( tr_peerIo * io, 325 struct evbuffer * inbuf, 326 uint32_t * setme ); 348 327 349 328 void tr_peerIoDrain( tr_peerIo * io, -
trunk/libtransmission/peer-msgs.c
r10998 r11299 307 307 } 308 308 309 static inlinevoid309 static void 310 310 dbgOutMessageLen( tr_peermsgs * msgs ) 311 311 { -
trunk/libtransmission/session.c
r11250 r11299 1162 1162 double * setme_KBps ) 1163 1163 { 1164 int Bps ;1164 int Bps = 0; 1165 1165 const tr_bool is_active = tr_sessionGetActiveSpeedLimit_Bps( session, dir, &Bps ); 1166 1166 *setme_KBps = toSpeedKBps( Bps ); -
trunk/libtransmission/torrent.c
r11264 r11299 402 402 { 403 403 uint16_t idleMinutes; 404 #warning can this use the idleSecs from tr_stat?405 404 return tr_torrentGetSeedIdle( tor, &idleMinutes ) 406 405 && difftime(tr_time(), MAX(tor->startDate, tor->activityDate)) >= idleMinutes * 60u; -
trunk/libtransmission/tr-lpd.c
r11091 r11299 255 255 /** 256 256 * @brief Configures additional capabilities for a socket */ 257 static inline int lpd_configureSocket( int sock, int add ) 257 static int 258 lpd_configureSocket( int sock, int add ) 258 259 { 259 260 #ifdef WIN32 -
trunk/libtransmission/utils.c
r11298 r11299 328 328 tr_lockUnlock( getMessageLock( ) ); 329 329 errno = err; 330 } 331 332 /*** 333 **** 334 ***/ 335 336 void* 337 tr_malloc( size_t size ) 338 { 339 return size ? malloc( size ) : NULL; 340 } 341 342 void* 343 tr_malloc0( size_t size ) 344 { 345 return size ? calloc( 1, size ) : NULL; 346 } 347 348 void 349 tr_free( void * p ) 350 { 351 if( p != NULL ) 352 free( p ); 353 } 354 355 void* 356 tr_memdup( const void * src, size_t byteCount ) 357 { 358 return memcpy( tr_malloc( byteCount ), src, byteCount ); 330 359 } 331 360 … … 662 691 663 692 char* 693 tr_strdup( const void * in ) 694 { 695 return tr_strndup( in, in ? (int)strlen((const char *)in) : 0 ); 696 } 697 698 char* 664 699 tr_strndup( const void * in, int len ) 665 700 { … … 1129 1164 ***/ 1130 1165 1166 void 1167 tr_removeElementFromArray( void * array, 1168 unsigned int index_to_remove, 1169 size_t sizeof_element, 1170 size_t nmemb ) 1171 { 1172 char * a = (char*) array; 1173 1174 memmove( a + sizeof_element * index_to_remove, 1175 a + sizeof_element * ( index_to_remove + 1 ), 1176 sizeof_element * ( --nmemb - index_to_remove ) ); 1177 } 1178 1131 1179 int 1132 1180 tr_lowerBound( const void * key, -
trunk/libtransmission/utils.h
r11250 r11299 296 296 297 297 /** @brief Portability wrapper around malloc() in which `0' is a safe argument */ 298 static inline void* tr_malloc( size_t size ) 299 { 300 return size ? malloc( size ) : NULL; 301 } 298 void* tr_malloc( size_t size ); 302 299 303 300 /** @brief Portability wrapper around calloc() in which `0' is a safe argument */ 304 static inline void* tr_malloc0( size_t size ) 305 { 306 return size ? calloc( 1, size ) : NULL; 307 } 301 void* tr_malloc0( size_t size ); 308 302 309 303 /** @brief Portability wrapper around free() in which `NULL' is a safe argument */ 310 static inline void tr_free( void * p ) 311 { 312 if( p != NULL ) 313 free( p ); 314 } 304 void tr_free( void * p ); 315 305 316 306 /** … … 320 310 * @return a newly-allocated copy of `src' that can be freed with tr_free() 321 311 */ 322 static inline void* tr_memdup( const void * src, size_t byteCount ) 323 { 324 return memcpy( tr_malloc( byteCount ), src, byteCount ); 325 } 312 void* tr_memdup( const void * src, size_t byteCount ); 326 313 327 314 #define tr_new( struct_type, n_structs ) \ … … 349 336 * @return a newly-allocated copy of `in' that can be freed with tr_free() 350 337 */ 351 static inline char* tr_strdup( const void * in ) 352 { 353 return tr_strndup( in, in ? (int)strlen((const char *)in) : 0 ); 354 } 338 char* tr_strdup( const void * in ); 355 339 356 340 /** @brief similar to bsearch() but returns the index of the lower bound */ … … 521 505 522 506 /** @brief convenience function to remove an item from an array */ 523 static inline void tr_removeElementFromArray( void * array, 524 unsigned int index_to_remove, 525 size_t sizeof_element, 526 size_t nmemb ) 527 { 528 char * a = (char*) array; 529 530 memmove( a + sizeof_element * index_to_remove, 531 a + sizeof_element * ( index_to_remove + 1 ), 532 sizeof_element * ( --nmemb - index_to_remove ) ); 533 } 507 void tr_removeElementFromArray( void * array, 508 unsigned int index_to_remove, 509 size_t sizeof_element, 510 size_t nmemb ); 534 511 535 512 /***
Note: See TracChangeset
for help on using the changeset viewer.