From 30a989f1df9044d9230e4c64c6488b202ec00d95 Mon Sep 17 00:00:00 2001 From: Charles Kerr Date: Mon, 5 Jan 2009 18:20:47 +0000 Subject: [PATCH] (trunk libT) fix the new-code errors reported by ZogG and Rolcol and Spaham --- libtransmission/peer-io.c | 17 +++++++++++++---- libtransmission/peer-io.h | 2 ++ libtransmission/peer-mgr.c | 2 +- libtransmission/request-list.c | 2 +- 4 files changed, 17 insertions(+), 6 deletions(-) diff --git a/libtransmission/peer-io.c b/libtransmission/peer-io.c index 1b2f7d0a2..7f50125e1 100644 --- a/libtransmission/peer-io.c +++ b/libtransmission/peer-io.c @@ -191,13 +191,14 @@ event_read_cb( int fd, short event UNUSED, void * vio ) size_t howmuch; const tr_direction dir = TR_DOWN; const size_t max = 256 * 1024; - const size_t curlen = EVBUFFER_LENGTH( io->inbuf ); - - howmuch = curlen >= max ? 0 : max - curlen; - howmuch = tr_bandwidthClamp( &io->bandwidth, TR_DOWN, howmuch ); + size_t curlen; assert( tr_isPeerIo( io ) ); + curlen = EVBUFFER_LENGTH( io->inbuf ); + howmuch = curlen >= max ? 0 : max - curlen; + howmuch = tr_bandwidthClamp( &io->bandwidth, TR_DOWN, howmuch ); + dbgmsg( io, "libevent says this peer is ready to read" ); /* if we don't have any bandwidth left, stop reading */ @@ -496,6 +497,14 @@ tr_peerIoSetIOFuncs( tr_peerIo * io, io->userData = userData; } +void +tr_peerIoClear( tr_peerIo * io ) +{ + tr_peerIoSetIOFuncs( io, NULL, NULL, NULL, NULL ); + tr_peerIoSetEnabled( io, TR_UP, FALSE ); + tr_peerIoSetEnabled( io, TR_DOWN, FALSE ); +} + int tr_peerIoReconnect( tr_peerIo * io ) { diff --git a/libtransmission/peer-io.h b/libtransmission/peer-io.h index 92437c6c5..f501149bb 100644 --- a/libtransmission/peer-io.h +++ b/libtransmission/peer-io.h @@ -210,6 +210,8 @@ void tr_peerIoSetIOFuncs ( tr_peerIo * io, tr_net_error_cb errcb, void * user_data ); +void tr_peerIoClear ( tr_peerIo * io ); + /** *** **/ diff --git a/libtransmission/peer-mgr.c b/libtransmission/peer-mgr.c index aa618d7dc..943ce4495 100644 --- a/libtransmission/peer-mgr.c +++ b/libtransmission/peer-mgr.c @@ -355,7 +355,7 @@ peerDestructor( tr_peer * peer ) tr_peerMsgsFree( peer->msgs ); } - tr_peerIoSetIOFuncs( peer->io, NULL, NULL, NULL, NULL ); + tr_peerIoClear( peer->io ); tr_peerIoUnref( peer->io ); /* balanced by the ref in handshakeDoneCB() */ tr_bitfieldFree( peer->have ); diff --git a/libtransmission/request-list.c b/libtransmission/request-list.c index a1541a1ee..04fef6aad 100644 --- a/libtransmission/request-list.c +++ b/libtransmission/request-list.c @@ -106,7 +106,7 @@ reqListRemoveFromSorted( struct request_list * list, const struct peer_request * static void reqListRemoveNthFromFifo( struct request_list * list, int n ) { - memmove( &list->fifo[n], &list->fifo[n+1], (list->len-1)*sizeof(struct peer_request)); + memmove( &list->fifo[n], &list->fifo[n+1], (list->len-n-1)*sizeof(struct peer_request)); } tr_bool