From 9513fcbe66ba8e4ad713567053133d4c036b7c8b Mon Sep 17 00:00:00 2001 From: Charles Kerr Date: Tue, 2 Jun 2009 18:21:23 +0000 Subject: [PATCH] (trunk libT) add a bunch of comments denoting where the libevent 2.0 changes will go --- libtransmission/bencode.c | 1 - libtransmission/bencode.h | 13 ++++++++----- libtransmission/peer-io.c | 5 +++++ libtransmission/peer-msgs.c | 3 ++- libtransmission/rpc-server.c | 4 ++++ libtransmission/rpcimpl.h | 1 + libtransmission/torrent.c | 5 +++++ libtransmission/utils.c | 3 ++- 8 files changed, 27 insertions(+), 8 deletions(-) diff --git a/libtransmission/bencode.c b/libtransmission/bencode.c index c6a14e046..6af846480 100644 --- a/libtransmission/bencode.c +++ b/libtransmission/bencode.c @@ -17,7 +17,6 @@ #include #include #include -#include /* close() */ #include #include /* close() */ diff --git a/libtransmission/bencode.h b/libtransmission/bencode.h index 2d5681dea..7cdd6e4d8 100644 --- a/libtransmission/bencode.h +++ b/libtransmission/bencode.h @@ -34,6 +34,7 @@ struct evbuffer; */ /* these are PRIVATE IMPLEMENTATION details that should not be touched. + * I'll probably change them just to break your code! HA HA HA! * it's included in the header for inlining and composition */ enum { @@ -45,7 +46,8 @@ enum TR_TYPE_REAL = 32 }; -/* these are PRIVATE IMPLEMENTATION details that should not be touched. +/* These are PRIVATE IMPLEMENTATION details that should not be touched. + * I'll probably change them just to break your code! HA HA HA! * it's included in the header for inlining and composition */ typedef struct tr_benc { @@ -61,8 +63,8 @@ typedef struct tr_benc { size_t len; /* the string length */ union { - char buf[16]; /* a local buffer */ - char * ptr; /* alloc'ed string */ + char buf[16]; /* local buffer for short strings */ + char * ptr; /* alloc'ed pointer for long strings */ } str; } s; @@ -108,7 +110,7 @@ void tr_bencInitBool( tr_benc *, int value ); void tr_bencInitReal( tr_benc *, double value ); /*** -**** +**** Serialization / Deserialization ***/ typedef enum @@ -123,7 +125,7 @@ int tr_bencToFile( const tr_benc *, tr_fmt_mode, const char * filename ); char* tr_bencToStr( const tr_benc *, tr_fmt_mode, int * len ); -void tr_bencToBuf( const tr_benc *, tr_fmt_mode, struct evbuffer * ); +void tr_bencToBuf( const tr_benc *, tr_fmt_mode, struct evbuffer * ); /* TR_FMT_JSON_LEAN and TR_FMT_JSON are equivalent in this function. */ int tr_bencLoadFile( tr_benc * setme, tr_fmt_mode, const char * filename ); @@ -229,6 +231,7 @@ int tr_bencParseStr( const uint8_t * buf, *** **/ +/* this is only quasi-supported. don't rely on it too heavily outside of libT */ void tr_bencMergeDicts( tr_benc * target, const tr_benc * source ); /* @} */ diff --git a/libtransmission/peer-io.c b/libtransmission/peer-io.c index 992b8ca1f..ccd2f4489 100644 --- a/libtransmission/peer-io.c +++ b/libtransmission/peer-io.c @@ -683,6 +683,7 @@ tr_peerIoWrite( tr_peerIo * io, size_t byteCount, tr_bool isPieceData ) { + /* FIXME(libevent2): this implementation snould be moved to tr_peerIoWriteBuf. This function should be implemented as evbuffer_new() + evbuffer_add_reference() + a call to tr_peerIoWriteBuf() + evbuffer_free() */ struct tr_datatype * datatype; assert( tr_amInEventThread( io->session ) ); @@ -699,6 +700,7 @@ tr_peerIoWrite( tr_peerIo * io, { case PEER_ENCRYPTION_RC4: { + /* FIXME(libevent2): use evbuffer_reserve_space() and evbuffer_commit_space() instead of tmp */ uint8_t tmp[MAX_STACK_ARRAY_SIZE]; const uint8_t * walk = bytes; evbuffer_expand( io->outbuf, byteCount ); @@ -728,6 +730,7 @@ tr_peerIoWriteBuf( tr_peerIo * io, struct evbuffer * buf, tr_bool isPieceData ) { + /* FIXME(libevent2): loop through calls to evbuffer_get_contiguous_space() + evbuffer_drain() */ const size_t n = EVBUFFER_LENGTH( buf ); tr_peerIoWrite( io, EVBUFFER_DATA( buf ), n, isPieceData ); evbuffer_drain( buf, n ); @@ -744,6 +747,7 @@ tr_peerIoReadBytes( tr_peerIo * io, size_t byteCount ) { assert( tr_isPeerIo( io ) ); + /* FIXME(libevent2): use evbuffer_get_length() */ assert( EVBUFFER_LENGTH( inbuf ) >= byteCount ); switch( io->encryptionMode ) @@ -753,6 +757,7 @@ tr_peerIoReadBytes( tr_peerIo * io, break; case PEER_ENCRYPTION_RC4: + /* FIXME(libevent2): loop through calls to evbuffer_get_contiguous_space() + evbuffer_drain() */ tr_cryptoDecrypt( io->crypto, byteCount, EVBUFFER_DATA(inbuf), bytes ); evbuffer_drain(inbuf, byteCount ); break; diff --git a/libtransmission/peer-msgs.c b/libtransmission/peer-msgs.c index 15f4fdb81..89f32c857 100644 --- a/libtransmission/peer-msgs.c +++ b/libtransmission/peer-msgs.c @@ -219,6 +219,7 @@ myDebug( const char * file, int line, evbuffer_add_vprintf( buf, fmt, args ); va_end( args ); evbuffer_add_printf( buf, " (%s:%d)\n", base, line ); + /* FIXME(libevent2) tr_getLog() should return an fd, then use evbuffer_write() here */ fwrite( EVBUFFER_DATA( buf ), 1, EVBUFFER_LENGTH( buf ), fp ); tr_free( base ); @@ -1718,6 +1719,7 @@ fillOutputBuffer( tr_peermsgs * msgs, time_t now ) if( requestIsValid( msgs, &req ) && tr_cpPieceIsComplete( &msgs->torrent->completion, req.index ) ) { + /* FIXME(libevent2): we can eliminate "buf" and an extra memcpy if we create an evbuffer here, add the message header, then use evbuffer_reserve_space() + tr_ioRead() + evbuffer_commit_space() */ int err; static uint8_t buf[MAX_BLOCK_SIZE]; @@ -1734,7 +1736,6 @@ fillOutputBuffer( tr_peermsgs * msgs, time_t now ) tr_peerIoWriteUint8 ( io, out, BT_PIECE ); tr_peerIoWriteUint32( io, out, req.index ); tr_peerIoWriteUint32( io, out, req.offset ); - /* FIXME(libevent2): use evbuffer_add_reference() */ tr_peerIoWriteBytes ( io, out, buf, req.length ); tr_peerIoWriteBuf( io, out, TRUE ); bytesWritten += EVBUFFER_LENGTH( out ); diff --git a/libtransmission/rpc-server.c b/libtransmission/rpc-server.c index 0c2bbac4e..4d75e45bf 100644 --- a/libtransmission/rpc-server.c +++ b/libtransmission/rpc-server.c @@ -324,6 +324,9 @@ add_response( struct evhttp_request * req, { int state; + /* FIXME(libevent2): this won't compile under libevent2. + but we can use evbuffer_reserve_space() + evbuffer_commit_space() instead */ + server->stream.next_in = (Bytef*) content; server->stream.avail_in = content_len; @@ -478,6 +481,7 @@ struct rpc_response_data struct tr_rpc_server * server; }; +/* FIXME(libevent2): make "response" an evbuffer and remove response_len */ static void rpc_response_func( tr_session * session UNUSED, const char * response, diff --git a/libtransmission/rpcimpl.h b/libtransmission/rpcimpl.h index a92ce335f..4c01bc936 100644 --- a/libtransmission/rpcimpl.h +++ b/libtransmission/rpcimpl.h @@ -23,6 +23,7 @@ extern "C" { struct tr_benc; +/* FIXME(libevent2): make "response" an evbuffer and remove response_len */ typedef void( *tr_rpc_response_func )( tr_session * session, const char * response, size_t response_len, diff --git a/libtransmission/torrent.c b/libtransmission/torrent.c index 19c4ee8ba..c50f2638f 100644 --- a/libtransmission/torrent.c +++ b/libtransmission/torrent.c @@ -1339,6 +1339,11 @@ tr_torrentCloseLocalFiles( const tr_torrent * tor ) assert( tr_isTorrent( tor ) ); + /* FIXME(libevent2) we're just using the evbuffer to build a key here anyway. + so we do (tor->info.fileCount * fd.openFileLimit) strcmps for these keys. :/ + it would be more efficient to remove this code altogether and + add "int torrentId;" to "struct tr_openfile", and a new function + tr_fdCloseTorrentFiles( tr_session*, int torrentId ) */ for( i=0; iinfo.fileCount; ++i ) { const tr_file * file = &tor->info.files[i]; diff --git a/libtransmission/utils.c b/libtransmission/utils.c index 0f745a585..798c9938c 100644 --- a/libtransmission/utils.c +++ b/libtransmission/utils.c @@ -270,8 +270,9 @@ tr_deepLog( const char * file, evbuffer_add_vprintf( buf, fmt, args ); va_end( args ); evbuffer_add_printf( buf, " (%s:%d)\n", base, line ); + /* FIXME(libevent2) ifdef this out for nonwindows platforms */ OutputDebugString( EVBUFFER_DATA( buf ) ); - if(fp) + if(fp) /* FIXME(libevent2) tr_getLog() should return an fd, then use evbuffer_write() here ) */ (void) fwrite( EVBUFFER_DATA( buf ), 1, EVBUFFER_LENGTH( buf ), fp ); tr_free( base );