Changeset 7546
- Timestamp:
- Dec 30, 2008, 8:25:39 AM (12 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/libtransmission/peer-msgs.c
r7540 r7546 78 78 PEX_INTERVAL = ( 90 * 1000 ), /* msec between sendPex() calls */ 79 79 80 MAX_QUEUE_SIZE = ( 100 ), 80 81 MAX_BLOCK_SIZE = ( 1024 * 16 ), 82 81 83 82 84 /* how long an unsent request can stay queued before it's returned … … 868 870 869 871 static void 870 expireOldRequests( tr_peermsgs * msgs, const time_t now ) 872 expireFromList( tr_peermsgs * msgs, 873 struct request_list * list, 874 const time_t oldestAllowed ) 871 875 { 872 876 int i; 873 time_t oldestAllowed; 874 struct request_list tmp = REQUEST_LIST_INIT; 875 const tr_bool fext = tr_peerIoSupportsFEXT( msgs->peer->io ); 876 dbgmsg( msgs, "entering `expire old requests' block" ); 877 878 /* cancel requests that have been queued for too long */ 879 oldestAllowed = now - QUEUED_REQUEST_TTL_SECS; 880 reqListCopy( &tmp, &msgs->clientWillAskFor ); 881 for( i=0; i<tmp.count; ++i ) { 882 const struct peer_request * req = &tmp.requests[i]; 877 878 /* walk through the list, looking for the first req that's too old */ 879 for( i=0; i<list->count; ++i ) { 880 const struct peer_request * req = &list->requests[i]; 883 881 if( req->time_requested < oldestAllowed ) 884 tr_peerMsgsCancel( msgs, req->index, req->offset, req->length ); 885 } 886 reqListClear( &tmp ); 887 888 /* if the peer doesn't support "Reject Request", 889 * cancel requests that were sent too long ago. */ 890 if( !fext ) { 891 oldestAllowed = now - SENT_REQUEST_TTL_SECS; 892 reqListCopy( &tmp, &msgs->clientAskedFor ); 893 for( i=0; i<tmp.count; ++i ) { 882 break; 883 } 884 885 /* if we found one too old, start pruning them */ 886 if( i < list->count ) { 887 struct request_list tmp = REQUEST_LIST_INIT; 888 reqListCopy( &tmp, list ); 889 for( ; i<tmp.count; ++i ) { 894 890 const struct peer_request * req = &tmp.requests[i]; 895 891 if( req->time_requested < oldestAllowed ) … … 897 893 } 898 894 reqListClear( &tmp ); 895 } 896 } 897 898 static void 899 expireOldRequests( tr_peermsgs * msgs, const time_t now ) 900 { 901 time_t oldestAllowed; 902 const tr_bool fext = tr_peerIoSupportsFEXT( msgs->peer->io ); 903 dbgmsg( msgs, "entering `expire old requests' block" ); 904 905 /* cancel requests that have been queued for too long */ 906 oldestAllowed = now - QUEUED_REQUEST_TTL_SECS; 907 expireFromList( msgs, &msgs->clientWillAskFor, oldestAllowed ); 908 909 /* if the peer doesn't support "Reject Request", 910 * cancel requests that were sent too long ago. */ 911 if( !fext ) { 912 oldestAllowed = now - SENT_REQUEST_TTL_SECS; 913 expireFromList( msgs, &msgs->clientAskedFor, oldestAllowed ); 899 914 } 900 915 … … 1818 1833 && tr_cpPieceIsComplete( msgs->torrent->completion, req.index ) ) 1819 1834 { 1835 int err; 1836 static uint8_t * buf = NULL; 1837 static struct evbuffer * out = NULL; 1838 1839 if( buf == NULL ) 1840 buf = tr_new( uint8_t, MAX_BLOCK_SIZE ); 1841 if( out == NULL ) 1842 out = evbuffer_new( ); 1843 1844 assert( !EVBUFFER_LENGTH( out ) ); 1845 1820 1846 /* send a block */ 1821 uint8_t * buf = tr_new( uint8_t, req.length ); 1822 const int err = tr_ioRead( msgs->torrent, req.index, req.offset, req.length, buf ); 1823 if( err ) { 1847 if(( err = tr_ioRead( msgs->torrent, req.index, req.offset, req.length, buf ))) { 1824 1848 fireError( msgs, err ); 1825 1849 bytesWritten = 0; … … 1827 1851 } else { 1828 1852 tr_peerIo * io = msgs->peer->io; 1829 struct evbuffer * out = evbuffer_new( );1830 1853 dbgmsg( msgs, "sending block %u:%u->%u", req.index, req.offset, req.length ); 1831 1854 tr_peerIoWriteUint32( io, out, sizeof( uint8_t ) + 2 * sizeof( uint32_t ) + req.length ); … … 1836 1859 tr_peerIoWriteBuf( io, out, TRUE ); 1837 1860 bytesWritten += EVBUFFER_LENGTH( out ); 1838 evbuffer_free( out );1839 1861 msgs->clientSentAnythingAt = now; 1840 1862 } 1841 tr_free( buf );1842 1863 } 1843 1864 else if( fext ) /* peer needs a reject message */
Note: See TracChangeset
for help on using the changeset viewer.