Changeset 12303


Ignore:
Timestamp:
Apr 4, 2011, 4:45:41 AM (11 years ago)
Author:
jordan
Message:

(trunk libT) when reading piece data in from a socket, avoid two unnecessary calls to memcpy()

Location:
trunk/libtransmission
Files:
6 edited

Legend:

Unmodified
Added
Removed
  • trunk/libtransmission/peer-io.c

    r12282 r12303  
    10621062
    10631063void
     1064tr_peerIoReadBytesToBuf( tr_peerIo * io, struct evbuffer * inbuf, struct evbuffer * outbuf, size_t byteCount )
     1065{
     1066    const size_t old_length = evbuffer_get_length( outbuf );
     1067
     1068    assert( tr_isPeerIo( io ) );
     1069    assert( evbuffer_get_length( inbuf )  >= byteCount );
     1070
     1071    /* append it to outbuf */
     1072    evbuffer_remove_buffer( inbuf, outbuf, byteCount );
     1073
     1074    /* decrypt if needed */
     1075    if( io->encryption_type == PEER_ENCRYPTION_RC4 ) {
     1076        struct evbuffer_ptr pos;
     1077        struct evbuffer_iovec iovec;
     1078        evbuffer_ptr_set( outbuf, &pos, old_length, EVBUFFER_PTR_SET );
     1079        do {
     1080           evbuffer_peek( outbuf, byteCount, &pos, &iovec, 1 );
     1081            tr_cryptoDecrypt( io->crypto, iovec.iov_len, iovec.iov_base, iovec.iov_base );
     1082        } while( !evbuffer_ptr_set( outbuf, &pos, iovec.iov_len, EVBUFFER_PTR_ADD ) );
     1083    }
     1084}
     1085
     1086void
    10641087tr_peerIoReadBytes( tr_peerIo * io, struct evbuffer * inbuf, void * bytes, size_t byteCount )
    10651088{
     
    11071130                size_t            byteCount )
    11081131{
    1109     void * buf = tr_sessionGetBuffer( io->session );
    1110     const size_t buflen = SESSION_BUFFER_SIZE;
     1132    char buf[4096];
     1133    const size_t buflen = sizeof( buf );
    11111134
    11121135    while( byteCount > 0 )
     
    11161139        byteCount -= thisPass;
    11171140    }
    1118 
    1119     tr_sessionReleaseBuffer( io->session );
    11201141}
    11211142
  • trunk/libtransmission/peer-io.h

    r12282 r12303  
    317317}
    318318
     319void tr_peerIoReadBytesToBuf( tr_peerIo       * io,
     320                              struct evbuffer * inbuf,
     321                              struct evbuffer * outbuf,
     322                              size_t            byteCount );
     323
    319324void tr_peerIoReadBytes( tr_peerIo        * io,
    320325                         struct evbuffer  * inbuf,
  • trunk/libtransmission/peer-mgr.c

    r12299 r12303  
    31583158        if( tor->isRunning ) {
    31593159            Torrent * t = tor->torrentPeers;
    3160             if( tr_ptrArraySize( &t->peers ) == 0 )
     3160            if( tr_ptrArrayEmpty( &t->peers ) )
    31613161                continue;
    31623162            rechokeUploads( t, now );
  • trunk/libtransmission/peer-msgs.c

    r12276 r12303  
    13091309        const size_t nLeft = req->length - evbuffer_get_length( msgs->incoming.block );
    13101310        size_t n = MIN( nLeft, inlen );
    1311         size_t i = n;
    1312         void * buf = tr_sessionGetBuffer( getSession( msgs ) );
    1313         const size_t buflen = SESSION_BUFFER_SIZE;
    1314 
    1315         while( i > 0 )
    1316         {
    1317             const size_t thisPass = MIN( i, buflen );
    1318             tr_peerIoReadBytes( msgs->peer->io, inbuf, buf, thisPass );
    1319             evbuffer_add( msgs->incoming.block, buf, thisPass );
    1320             i -= thisPass;
    1321         }
    1322 
    1323         tr_sessionReleaseBuffer( getSession( msgs ) );
    1324         buf = NULL;
     1311
     1312        tr_peerIoReadBytesToBuf( msgs->peer->io, inbuf, msgs->incoming.block, n );
    13251313
    13261314        fireClientGotData( msgs, n, true );
  • trunk/libtransmission/session.c

    r12280 r12303  
    572572    session->tag = tr_strdup( tag );
    573573    session->magicNumber = SESSION_MAGIC_NUMBER;
    574     session->buffer = tr_valloc( SESSION_BUFFER_SIZE );
    575574    tr_bandwidthConstruct( &session->bandwidth, session, NULL );
    576575    tr_peerIdInit( session->peer_id );
     
    10101009***/
    10111010
    1012 void*
    1013 tr_sessionGetBuffer( tr_session * session )
    1014 {
    1015     assert( tr_isSession( session ) );
    1016     assert( !session->bufferInUse );
    1017     assert( tr_amInEventThread( session ) );
    1018 
    1019     session->bufferInUse = true;
    1020     return session->buffer;
    1021 }
    1022 
    1023 void
    1024 tr_sessionReleaseBuffer( tr_session * session )
    1025 {
    1026     assert( tr_isSession( session ) );
    1027     assert( session->bufferInUse );
    1028     assert( tr_amInEventThread( session ) );
    1029 
    1030     session->bufferInUse = false;
    1031 }
    1032 
    10331011void
    10341012tr_sessionLock( tr_session * session )
     
    18631841    }
    18641842    tr_free( session->torrentDoneScript );
    1865     tr_free( session->buffer );
    18661843    tr_free( session->tag );
    18671844    tr_free( session->configDir );
  • trunk/libtransmission/session.h

    r12281 r12303  
    207207    struct tr_bindinfo         * public_ipv6;
    208208
    209     /* a page-aligned buffer for use by the libtransmission thread.
    210      * @see SESSION_BUFFER_SIZE */
    211     void * buffer;
    212 
    213     bool bufferInUse;
    214 
    215209    tr_web_config_func          * curl_easy_config_func;
    216210
     
    262256{
    263257    SESSION_MAGIC_NUMBER = 3845,
    264 
    265     /* @see tr_session.buffer */
    266     SESSION_BUFFER_SIZE = (16*1024)
    267258};
    268 
    269 void* tr_sessionGetBuffer( tr_session * session );
    270 
    271 void tr_sessionReleaseBuffer( tr_session * session );
    272259
    273260static inline bool tr_isSession( const tr_session * session )
Note: See TracChangeset for help on using the changeset viewer.