* $Id$
*/
+#include <event2/buffer.h>
+
#include "transmission.h"
#include "cache.h"
#include "inout.h"
time_t time;
tr_block_index_t block;
- uint8_t * buf;
+ struct evbuffer * evbuf;
};
struct tr_cache
for( i=pos; i<pos+n; ++i ) {
b = blocks[i];
- memcpy( walk, b->buf, b->length );
+ evbuffer_copyout( b->evbuf, walk, b->length );
walk += b->length;
- tr_free( b->buf );
+ evbuffer_free( b->evbuf );
tr_free( b );
}
tr_ptrArrayErase( &cache->blocks, pos, pos+n );
tr_piece_index_t piece,
uint32_t offset,
uint32_t length,
- const uint8_t * writeme )
+ struct evbuffer * writeme )
{
struct cache_block * cb = findBlock( cache, torrent, piece, offset );
cb->offset = offset;
cb->length = length;
cb->block = _tr_block( torrent, piece, offset );
- cb->buf = NULL;
+ cb->evbuf = evbuffer_new( );
tr_ptrArrayInsertSorted( &cache->blocks, cb, cache_block_compare );
}
cb->time = tr_time();
- tr_free( cb->buf );
- cb->buf = tr_memdup( writeme, cb->length );
+ assert( cb->length == length );
+ evbuffer_drain( cb->evbuf, evbuffer_get_length( cb->evbuf ) );
+ evbuffer_remove_buffer( writeme, cb->evbuf, cb->length );
++cache->cache_writes;
cache->cache_write_bytes += cb->length;
struct cache_block * cb = findBlock( cache, torrent, piece, offset );
if( cb )
- memcpy( setme, cb->buf, len );
+ evbuffer_copyout( cb->evbuf, setme, len );
else
err = tr_ioRead( torrent, piece, offset, len, setme );
}
static int clientGotBlock( tr_peermsgs * msgs,
- const uint8_t * block,
+ struct evbuffer * block,
const struct peer_request * req );
static int
return READ_LATER;
/* we've got the whole block ... process it */
- err = clientGotBlock( msgs, evbuffer_pullup( msgs->incoming.block, -1 ), req );
+ err = clientGotBlock( msgs, msgs->incoming.block, req );
/* cleanup */
evbuffer_free( msgs->incoming.block );
/* returns 0 on success, or an errno on failure */
static int
clientGotBlock( tr_peermsgs * msgs,
- const uint8_t * data,
+ struct evbuffer * data,
const struct peer_request * req )
{
int err;
tr_cacheWriteBlock( session->cache, tor,
t->piece_index, t->piece_offset, t->length,
- evbuffer_pullup( t->content, -1 ) );
+ t->content );
fire_client_got_block( tor, w, t->block );
tr_list_remove_data( &w->tasks, t );