(trunk libT) use ssize_t where appropriate in tr_peerIoFlush()

This commit is contained in:
Charles Kerr 2009-01-03 04:57:40 +00:00
parent 1e77d1313e
commit 5afd327b15
4 changed files with 28 additions and 29 deletions

View File

@ -219,12 +219,12 @@ tr_bandwidthAllocate( tr_bandwidth * b,
i = n ? tr_cryptoWeakRandInt( n ) : 0; /* pick a random starting point */
while( n > 1 )
{
const int increment = 1024;
const int bytesUsed = tr_peerIoFlush( peers[i], dir, increment );
const size_t increment = 1024;
const ssize_t bytesUsed = tr_peerIoFlush( peers[i], dir, increment );
dbgmsg( "peer #%d of %d used %.2f KiB in this pass", i, n, bytesUsed/1024.0 );
dbgmsg( "peer #%d of %d used %zd bytes in this pass", i, n, bytesUsed );
if( bytesUsed == increment )
if( bytesUsed == (ssize_t)increment )
++i;
else {
/* peer is done writing for now; move it to the end of the list */

View File

@ -233,12 +233,14 @@ event_read_cb( int fd, short event UNUSED, void * vio )
}
}
static int
static ssize_t
tr_evbuffer_write( tr_peerIo * io, int fd, size_t howmuch )
{
struct evbuffer * buffer = io->outbuf;
int n = MIN( EVBUFFER_LENGTH( buffer ), howmuch );
int e;
ssize_t n;
struct evbuffer * buffer = io->outbuf;
howmuch = MIN( EVBUFFER_LENGTH( buffer ), howmuch );
errno = 0;
#ifdef WIN32
@ -247,13 +249,10 @@ tr_evbuffer_write( tr_peerIo * io, int fd, size_t howmuch )
n = write(fd, buffer->buffer, n );
#endif
e = errno;
dbgmsg( io, "wrote %d to peer (%s)", n, (n==-1?strerror(e):"") );
dbgmsg( io, "wrote %zd to peer (%s)", n, (n==-1?strerror(e):"") );
if( n == -1 )
return -1;
if (n == 0)
return 0;
evbuffer_drain( buffer, n );
if( n > 0 )
evbuffer_drain( buffer, n );
return n;
}
@ -728,10 +727,10 @@ tr_peerIoDrain( tr_peerIo * io,
****
***/
static int
static ssize_t
tr_peerIoTryRead( tr_peerIo * io, size_t howmuch )
{
int res = 0;
ssize_t res = 0;
if(( howmuch = tr_bandwidthClamp( &io->bandwidth, TR_DOWN, howmuch )))
{
@ -740,7 +739,7 @@ tr_peerIoTryRead( tr_peerIo * io, size_t howmuch )
res = evbuffer_read( io->inbuf, io->socket, howmuch );
e = errno;
dbgmsg( io, "read %d from peer (%s)", res, (res==-1?strerror(e):"") );
dbgmsg( io, "read %zd from peer (%s)", res, (res==-1?strerror(e):"") );
if( EVBUFFER_LENGTH( io->inbuf ) )
canReadWrapper( io );
@ -750,7 +749,7 @@ tr_peerIoTryRead( tr_peerIo * io, size_t howmuch )
short what = EVBUFFER_READ | EVBUFFER_ERROR;
if( res == 0 )
what |= EVBUFFER_EOF;
dbgmsg( io, "tr_peerIoTryRead got an error. res is %d, what is %hd, errno is %d (%s)", res, what, e, strerror( e ) );
dbgmsg( io, "tr_peerIoTryRead got an error. res is %zd, what is %hd, errno is %d (%s)", res, what, e, strerror( e ) );
io->gotError( io, what, io->userData );
}
}
@ -758,16 +757,16 @@ tr_peerIoTryRead( tr_peerIo * io, size_t howmuch )
return res;
}
static int
static ssize_t
tr_peerIoTryWrite( tr_peerIo * io, size_t howmuch )
{
int n = 0;
ssize_t n = 0;
if(( howmuch = tr_bandwidthClamp( &io->bandwidth, TR_UP, howmuch )))
{
int e;
errno = 0;
n = tr_evbuffer_write( io, io->socket, (int)howmuch );
n = tr_evbuffer_write( io, io->socket, howmuch );
e = errno;
if( n > 0 )
@ -776,7 +775,7 @@ tr_peerIoTryWrite( tr_peerIo * io, size_t howmuch )
if( ( n < 0 ) && ( io->gotError ) && ( e != EPIPE ) && ( e != EAGAIN ) && ( e != EINTR ) && ( e != EINPROGRESS ) )
{
const short what = EVBUFFER_WRITE | EVBUFFER_ERROR;
dbgmsg( io, "tr_peerIoTryWrite got an error. res is %d, what is %hd, errno is %d (%s)", n, what, e, strerror( e ) );
dbgmsg( io, "tr_peerIoTryWrite got an error. res is %zd, what is %hd, errno is %d (%s)", n, what, e, strerror( e ) );
io->gotError( io, what, io->userData );
}
}
@ -784,20 +783,20 @@ tr_peerIoTryWrite( tr_peerIo * io, size_t howmuch )
return n;
}
int
ssize_t
tr_peerIoFlush( tr_peerIo * io, tr_direction dir, size_t limit )
{
int bytesUsed;
ssize_t bytesUsed;
assert( tr_isPeerIo( io ) );
assert( tr_isDirection( dir ) );
if( dir==TR_DOWN )
if( dir == TR_DOWN )
bytesUsed = tr_peerIoTryRead( io, limit );
else
bytesUsed = tr_peerIoTryWrite( io, limit );
dbgmsg( io, "flushing peer-io, direction %d, limit %zu, bytesUsed %d", (int)dir, limit, bytesUsed );
dbgmsg( io, "flushing peer-io, direction %d, limit %zu, bytesUsed %zd", (int)dir, limit, bytesUsed );
return bytesUsed;
}

View File

@ -348,7 +348,7 @@ void tr_peerIoSetEnabled( tr_peerIo * io,
tr_direction dir,
tr_bool isEnabled );
int tr_peerIoFlush( tr_peerIo * io,
ssize_t tr_peerIoFlush( tr_peerIo * io,
tr_direction dir,
size_t byteLimit );

View File

@ -225,12 +225,12 @@ tr_getLogTimeStr( char * buf,
tr_bool
tr_deepLoggingIsActive( void )
{
static tr_bool deepLoggingIsActive = -1;
static int8_t deepLoggingIsActive = -1;
if( deepLoggingIsActive == -1 )
if( deepLoggingIsActive < 0 )
deepLoggingIsActive = IsDebuggerPresent() || (tr_getLog()!=NULL);
return deepLoggingIsActive;
return deepLoggingIsActive != 0;
}
void