Changeset 7549


Ignore:
Timestamp:
Dec 30, 2008, 8:32:00 PM (12 years ago)
Author:
charles
Message:

(trunk libT) have a pool of reusable evbuffers

Location:
trunk/libtransmission
Files:
9 edited

Legend:

Unmodified
Added
Removed
  • trunk/libtransmission/bencode.c

    r7524 r7549  
    10441044    char *            ret;
    10451045    struct WalkFuncs  walkFuncs;
    1046     struct evbuffer * out = evbuffer_new( );
     1046    struct evbuffer * out = tr_getBuffer( );
    10471047
    10481048    walkFuncs.intFunc = saveIntFunc;
     
    10561056        *len = EVBUFFER_LENGTH( out );
    10571057    ret = tr_strndup( EVBUFFER_DATA( out ), EVBUFFER_LENGTH( out ) );
    1058     evbuffer_free( out );
     1058
     1059    tr_releaseBuffer( out );
    10591060    return ret;
    10601061}
     
    13181319    struct jsonWalk  data;
    13191320
    1320     data.out = evbuffer_new( );
     1321    data.out = tr_getBuffer( );
    13211322    data.parents = NULL;
    13221323
     
    13341335        *len = EVBUFFER_LENGTH( data.out );
    13351336    ret = tr_strndup( EVBUFFER_DATA( data.out ), EVBUFFER_LENGTH( data.out ) );
    1336     evbuffer_free( data.out );
     1337
     1338    tr_releaseBuffer( data.out );
    13371339    return ret;
    13381340}
  • trunk/libtransmission/clients.c

    r7526 r7549  
    411411    if( !*buf )
    412412    {
    413         struct evbuffer * out = evbuffer_new( );
     413        struct evbuffer * out = tr_getBuffer( );
    414414        const char *in, *in_end;
    415415        for( in=(const char*)id, in_end=in+8; in!=in_end; ++in ) {
     
    421421
    422422        tr_strlcpy( buf, EVBUFFER_DATA( out ), buflen );
    423         evbuffer_free( out );
    424     }
    425 }
     423        tr_releaseBuffer( out );
     424    }
     425}
  • trunk/libtransmission/handshake.c

    r7476 r7549  
    315315    int               len;
    316316    const uint8_t *   public_key;
    317     struct evbuffer * outbuf = evbuffer_new( );
     317    struct evbuffer * outbuf = tr_getBuffer( );
    318318    uint8_t           pad_a[PadA_MAXLEN];
    319319
     
    334334
    335335    /* cleanup */
    336     evbuffer_free( outbuf );
     336    tr_releaseBuffer( outbuf );
    337337}
    338338
     
    427427    /* now send these: HASH('req1', S), HASH('req2', SKEY) xor HASH('req3', S),
    428428     * ENCRYPT(VC, crypto_provide, len(PadC), PadC, len(IA)), ENCRYPT(IA) */
    429     outbuf = evbuffer_new( );
     429    outbuf = tr_getBuffer( );
    430430
    431431    /* HASH('req1', S) */
     
    484484
    485485    /* cleanup */
    486     evbuffer_free( outbuf );
     486    tr_releaseBuffer( outbuf );
    487487    return READ_LATER;
    488488}
     
    920920
    921921    tr_cryptoEncryptInit( handshake->crypto );
    922     outbuf = evbuffer_new( );
     922    outbuf = tr_getBuffer( );
    923923
    924924    dbgmsg( handshake, "sending vc" );
     
    969969    /* send it out */
    970970    tr_peerIoWriteBuf( handshake->io, outbuf, FALSE );
    971     evbuffer_free( outbuf );
     971    tr_releaseBuffer( outbuf );
    972972
    973973    /* now await the handshake */
  • trunk/libtransmission/metainfo.c

    r7476 r7549  
    6262{
    6363    char *            ret;
    64     struct evbuffer * buf = evbuffer_new( );
     64    struct evbuffer * buf = tr_getBuffer( );
    6565
    6666    evbuffer_add_printf( buf, "%s%c%s", tr_getTorrentDir( session ),
     
    7171
    7272    ret = tr_strndup( EVBUFFER_DATA( buf ), EVBUFFER_LENGTH( buf ) );
    73     evbuffer_free( buf );
     73    tr_releaseBuffer( buf );
    7474    return ret;
    7575}
     
    137137    else
    138138    {
    139         struct evbuffer * buf = evbuffer_new( );
     139        struct evbuffer * buf = tr_getBuffer( );
    140140        int               n = tr_bencListSize( path );
    141141        int               i;
     
    155155        *setme = tr_strndup( EVBUFFER_DATA( buf ), EVBUFFER_LENGTH( buf ) );
    156156        /* fprintf( stderr, "[%s]\n", *setme ); */
    157         evbuffer_free( buf );
     157        tr_releaseBuffer( buf );
    158158        err = 0;
    159159    }
     
    235235               strrchr( announce, '/' ) ) ) && !strncmp( ++s, "announce", 8 ) )
    236236    {
    237         struct evbuffer * buf = evbuffer_new( );
     237        struct evbuffer * buf = tr_getBuffer( );
    238238        evbuffer_add( buf, announce, s - announce );
    239239        evbuffer_add( buf, "scrape", 6 );
    240240        evbuffer_add_printf( buf, "%s", s + 8 );
    241241        scrape = tr_strdup( EVBUFFER_DATA( buf ) );
    242         evbuffer_free( buf );
     242        tr_releaseBuffer( buf );
    243243    }
    244244
  • trunk/libtransmission/peer-msgs.c

    r7548 r7549  
    330330        va_list           args;
    331331        char              timestr[64];
    332         struct evbuffer * buf = evbuffer_new( );
     332        struct evbuffer * buf = tr_getBuffer( );
    333333        char *            base = tr_basename( file );
    334334
     
    345345
    346346        tr_free( base );
    347         evbuffer_free( buf );
     347        tr_releaseBuffer( buf );
    348348    }
    349349}
     
    17591759            int err;
    17601760            static uint8_t * buf = NULL;
    1761             static struct evbuffer * out = NULL;
    17621761
    17631762            if( buf == NULL )
    17641763                buf = tr_new( uint8_t, MAX_BLOCK_SIZE );
    1765             if( out == NULL )
    1766                 out = evbuffer_new( );
    1767 
    1768             assert( !EVBUFFER_LENGTH( out ) );
    17691764
    17701765            /* send a block */
     
    17751770            } else {
    17761771                tr_peerIo * io = msgs->peer->io;
     1772                struct evbuffer * out = tr_getBuffer( );
    17771773                dbgmsg( msgs, "sending block %u:%u->%u", req.index, req.offset, req.length );
    17781774                tr_peerIoWriteUint32( io, out, sizeof( uint8_t ) + 2 * sizeof( uint32_t ) + req.length );
     
    17841780                bytesWritten += EVBUFFER_LENGTH( out );
    17851781                msgs->clientSentAnythingAt = now;
     1782                tr_releaseBuffer( out );
    17861783            }
    17871784        }
  • trunk/libtransmission/rpc-server.c

    r7479 r7549  
    7777{
    7878    const char *      code_text = tr_webGetResponseStr( code );
    79     struct evbuffer * body = evbuffer_new( );
     79    struct evbuffer * body = tr_getBuffer( );
    8080
    8181    evbuffer_add_printf( body, "<h1>%d: %s</h1>", code, code_text );
     
    8383        evbuffer_add_printf( body, "%s", text );
    8484    evhttp_send_reply( req, code, code_text, body );
    85     evbuffer_free( body );
     85
     86    tr_releaseBuffer( body );
    8687}
    8788
     
    320321
    321322            errno = error;
    322             out = evbuffer_new( );
     323            out = tr_getBuffer( );
    323324            evhttp_add_header( req->output_headers, "Content-Type",
    324325                               mimetype_guess( filename ) );
     
    326327            evhttp_send_reply( req, HTTP_OK, "OK", out );
    327328
    328             evbuffer_free( out );
     329            tr_releaseBuffer( out );
    329330            tr_free( content );
    330331        }
     
    399400    }
    400401
    401     buf = evbuffer_new( );
     402    buf = tr_getBuffer( );
    402403    add_response( req, buf, out, len );
    403404    evhttp_add_header( req->output_headers, "Content-Type",
     
    406407
    407408    /* cleanup */
    408     evbuffer_free( buf );
     409    tr_releaseBuffer( buf );
    409410    tr_free( out );
    410411}
  • trunk/libtransmission/utils.c

    r7543 r7549  
    4545
    4646#include "transmission.h"
     47#include "list.h"
    4748#include "utils.h"
    4849#include "platform.h"
     
    240241        va_list           args;
    241242        char              timestr[64];
    242         struct evbuffer * buf = evbuffer_new( );
     243        struct evbuffer * buf = tr_getBuffer( );
    243244        char *            base = tr_basename( file );
    244245
     
    256257
    257258        tr_free( base );
    258         evbuffer_free( buf );
     259        tr_releaseBuffer( buf );
    259260    }
    260261}
     
    685686    va_list           ap;
    686687
    687     buf = evbuffer_new( );
     688    buf = tr_getBuffer( );
    688689    va_start( ap, fmt );
    689690
     
    692693
    693694    va_end( ap );
    694     evbuffer_free( buf );
     695    tr_releaseBuffer( buf );
    695696    return ret;
    696697}
     
    12941295    return (void*)(intptr_t)i;
    12951296}
     1297
     1298/***
     1299****
     1300***/
     1301
     1302static tr_list * _bufferList = NULL;
     1303
     1304struct evbuffer*
     1305tr_getBuffer( void )
     1306{
     1307    struct evbuffer * buf = tr_list_pop_front( &_bufferList );
     1308    if( buf == NULL )
     1309        buf = evbuffer_new( );
     1310    assert( !EVBUFFER_LENGTH( buf ) );
     1311    return buf;
     1312}
     1313
     1314void
     1315tr_releaseBuffer( struct evbuffer * buf )
     1316{
     1317    evbuffer_drain( buf, EVBUFFER_LENGTH( buf ) );
     1318    tr_list_prepend( &_bufferList, buf );
     1319}
  • trunk/libtransmission/utils.h

    r7533 r7549  
    245245/* wait the specified number of milliseconds */
    246246void           tr_wait( uint64_t delay_milliseconds );
     247
     248/***
     249****
     250***/
     251
     252struct evbuffer;
     253
     254/** @brief pool of reusable buffers
     255    @see tr_releaseBuffer() */
     256struct evbuffer * tr_getBuffer( void );
     257
     258/** @brief return a buffer to the pool
     259    @see tr_getBuffer() */
     260void tr_releaseBuffer( struct evbuffer * buf );
     261
    247262
    248263/***
  • trunk/libtransmission/webseed.c

    r7404 r7549  
    100100{
    101101    char *            ret;
    102     struct evbuffer * out = evbuffer_new( );
     102    struct evbuffer * out = tr_getBuffer( );
    103103    const char *      url = w->url;
    104104    const size_t      url_len = strlen( url );
     
    141141
    142142    ret = tr_strndup( EVBUFFER_DATA( out ), EVBUFFER_LENGTH( out ) );
    143     evbuffer_free( out );
     143    tr_releaseBuffer( out );
    144144    return ret;
    145145}
Note: See TracChangeset for help on using the changeset viewer.