Changeset 7125 for trunk/libtransmission/peer-io.c
- Timestamp:
- Nov 17, 2008, 4:00:57 AM (14 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/libtransmission/peer-io.c
r7069 r7125 28 28 #include "transmission.h" 29 29 #include "crypto.h" 30 #include "list.h" 30 31 #include "net.h" 31 32 #include "peer-io.h" … … 77 78 }; 78 79 80 struct tr_datatype 81 { 82 unsigned int isPieceData : 1; 83 size_t length; 84 }; 85 79 86 struct tr_peerIo 80 87 { … … 93 100 time_t timeCreated; 94 101 95 tr_session *session;102 tr_session * session; 96 103 97 104 struct in_addr in_addr; 98 struct bufferevent * bufev; 99 struct evbuffer * output; 105 struct bufferevent * bufev; 106 struct evbuffer * output; 107 tr_list * output_datatypes; /* struct tr_datatype */ 100 108 101 109 tr_can_read_cb canRead; … … 200 208 if( len < io->bufferSize[TR_UP] ) 201 209 { 202 const size_t payload = io->bufferSize[TR_UP] - len; 203 const size_t n = addPacketOverhead( payload ); 204 struct tr_bandwidth * b = &io->bandwidth[TR_UP]; 205 b->bytesLeft -= MIN( b->bytesLeft, (size_t)n ); 206 b->bytesUsed += n; 207 tr_rcTransferred( io->session->rawSpeed[TR_UP], n ); 208 dbgmsg( io, 209 "wrote %zu bytes to peer... upload bytesLeft is now %zu", 210 n, 211 b->bytesLeft ); 210 size_t payload = io->bufferSize[TR_UP] - len; 211 212 while( payload ) 213 { 214 struct tr_datatype * next = io->output_datatypes->data; 215 const size_t chunk_length = MIN( next->length, payload ); 216 const size_t n = addPacketOverhead( chunk_length ); 217 218 if( next->isPieceData ) 219 { 220 struct tr_bandwidth * b = &io->bandwidth[TR_UP]; 221 b->bytesLeft -= MIN( b->bytesLeft, n ); 222 b->bytesUsed += n; 223 } 224 225 if( io->didWrite ) 226 io->didWrite( io, n, next->isPieceData, io->userData ); 227 228 payload -= chunk_length; 229 next->length -= chunk_length; 230 if( !next->length ) 231 tr_free( tr_list_pop_front( &io->output_datatypes ) ); 232 } 212 233 } 213 234 214 235 adjustOutputBuffer( io ); 215 236 216 if( io->didWrite )217 io->didWrite( e, io->userData );218 237 } 219 238 … … 238 257 b->bytesLeft -= MIN( b->bytesLeft, (size_t)n ); 239 258 b->bytesUsed += n; 240 tr_rcTransferred( io->session->rawSpeed[TR_DOWN], n ); 241 dbgmsg( io, 242 "%zu new input bytes. bytesUsed is %zu, bytesLeft is %zu", 243 n, b->bytesUsed, 244 b->bytesLeft ); 259 dbgmsg( io, "%zu new input bytes. bytesUsed is %zu, bytesLeft is %zu", n, b->bytesUsed, b->bytesLeft ); 245 260 246 261 adjustInputBuffer( io ); … … 387 402 tr_netClose( io->socket ); 388 403 tr_cryptoFree( io->crypto ); 404 tr_list_free( &io->output_datatypes, tr_free ); 389 405 tr_free( io ); 390 406 } … … 718 734 719 735 void 720 tr_peerIoWrite( tr_peerIo * io, 721 const void * writeme, 722 size_t writemeLen ) 723 { 736 tr_peerIoWrite( tr_peerIo * io, 737 const void * writeme, 738 size_t writemeLen, 739 int isPieceData ) 740 { 741 struct tr_datatype * datatype; 724 742 assert( tr_amInEventThread( io->session ) ); 725 743 dbgmsg( io, "adding %zu bytes into io->output", writemeLen ); … … 730 748 evbuffer_add( io->output, writeme, writemeLen ); 731 749 750 datatype = tr_new( struct tr_datatype, 1 ); 751 datatype->isPieceData = isPieceData != 0; 752 datatype->length = writemeLen; 753 tr_list_append( &io->output_datatypes, datatype ); 754 732 755 adjustOutputBuffer( io ); 733 756 } 734 757 735 758 void 736 tr_peerIoWriteBuf( tr_peerIo * io, 737 struct evbuffer * buf ) 759 tr_peerIoWriteBuf( tr_peerIo * io, 760 struct evbuffer * buf, 761 int isPieceData ) 738 762 { 739 763 const size_t n = EVBUFFER_LENGTH( buf ); 740 764 741 tr_peerIoWrite( io, EVBUFFER_DATA( buf ), n );765 tr_peerIoWrite( io, EVBUFFER_DATA( buf ), n, isPieceData ); 742 766 evbuffer_drain( buf, n ); 743 767 }
Note: See TracChangeset
for help on using the changeset viewer.