Changeset 7594


Ignore:
Timestamp:
Jan 3, 2009, 4:57:40 AM (12 years ago)
Author:
charles
Message:

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

Location:
trunk/libtransmission
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • trunk/libtransmission/bandwidth.c

    r7592 r7594  
    220220    while( n > 1 )
    221221    {
    222         const int increment = 1024;
    223         const int bytesUsed = tr_peerIoFlush( peers[i], dir, increment );
    224 
    225         dbgmsg( "peer #%d of %d used %.2f KiB in this pass", i, n, bytesUsed/1024.0 );
    226 
    227         if( bytesUsed == increment )
     222        const size_t increment = 1024;
     223        const ssize_t bytesUsed = tr_peerIoFlush( peers[i], dir, increment );
     224
     225        dbgmsg( "peer #%d of %d used %zd bytes in this pass", i, n, bytesUsed );
     226
     227        if( bytesUsed == (ssize_t)increment )
    228228            ++i;
    229229        else {
  • trunk/libtransmission/peer-io.c

    r7593 r7594  
    234234}
    235235
    236 static int
     236static ssize_t
    237237tr_evbuffer_write( tr_peerIo * io, int fd, size_t howmuch )
    238238{
     239    int e;
     240    ssize_t n;
    239241    struct evbuffer * buffer = io->outbuf;
    240     int n = MIN( EVBUFFER_LENGTH( buffer ), howmuch );
    241     int e;
     242
     243    howmuch = MIN( EVBUFFER_LENGTH( buffer ), howmuch );
    242244
    243245    errno = 0;
     
    248250#endif
    249251    e = errno;
    250     dbgmsg( io, "wrote %d to peer (%s)", n, (n==-1?strerror(e):"") );
    251 
    252     if( n == -1 )
    253         return -1;
    254     if (n == 0)
    255         return 0;
    256     evbuffer_drain( buffer, n );
     252    dbgmsg( io, "wrote %zd to peer (%s)", n, (n==-1?strerror(e):"") );
     253
     254    if( n > 0 )
     255        evbuffer_drain( buffer, n );
    257256
    258257    return n;
     
    729728***/
    730729
    731 static int
     730static ssize_t
    732731tr_peerIoTryRead( tr_peerIo * io, size_t howmuch )
    733732{
    734     int res = 0;
     733    ssize_t res = 0;
    735734
    736735    if(( howmuch = tr_bandwidthClamp( &io->bandwidth, TR_DOWN, howmuch )))
     
    741740        e = errno;
    742741
    743         dbgmsg( io, "read %d from peer (%s)", res, (res==-1?strerror(e):"") );
     742        dbgmsg( io, "read %zd from peer (%s)", res, (res==-1?strerror(e):"") );
    744743
    745744        if( EVBUFFER_LENGTH( io->inbuf ) )
     
    751750            if( res == 0 )
    752751                what |= EVBUFFER_EOF;
    753             dbgmsg( io, "tr_peerIoTryRead got an error. res is %d, what is %hd, errno is %d (%s)", res, what, e, strerror( e ) );
     752            dbgmsg( io, "tr_peerIoTryRead got an error. res is %zd, what is %hd, errno is %d (%s)", res, what, e, strerror( e ) );
    754753            io->gotError( io, what, io->userData );
    755754        }
     
    759758}
    760759
    761 static int
     760static ssize_t
    762761tr_peerIoTryWrite( tr_peerIo * io, size_t howmuch )
    763762{
    764     int n = 0;
     763    ssize_t n = 0;
    765764
    766765    if(( howmuch = tr_bandwidthClamp( &io->bandwidth, TR_UP, howmuch )))
     
    768767        int e;
    769768        errno = 0;
    770         n = tr_evbuffer_write( io, io->socket, (int)howmuch );
     769        n = tr_evbuffer_write( io, io->socket, howmuch );
    771770        e = errno;
    772771
     
    777776        {
    778777            const short what = EVBUFFER_WRITE | EVBUFFER_ERROR;
    779             dbgmsg( io, "tr_peerIoTryWrite got an error. res is %d, what is %hd, errno is %d (%s)", n, what, e, strerror( e ) );
     778            dbgmsg( io, "tr_peerIoTryWrite got an error. res is %zd, what is %hd, errno is %d (%s)", n, what, e, strerror( e ) );
    780779            io->gotError( io, what, io->userData );
    781780        }
     
    785784}
    786785
    787 int
     786ssize_t
    788787tr_peerIoFlush( tr_peerIo  * io, tr_direction dir, size_t limit )
    789788{
    790     int bytesUsed;
     789    ssize_t bytesUsed;
    791790
    792791    assert( tr_isPeerIo( io ) );
    793792    assert( tr_isDirection( dir ) );
    794793
    795     if( dir==TR_DOWN )
     794    if( dir == TR_DOWN )
    796795        bytesUsed = tr_peerIoTryRead( io, limit );
    797796    else
    798797        bytesUsed = tr_peerIoTryWrite( io, limit );
    799798
    800     dbgmsg( io, "flushing peer-io, direction %d, limit %zu, bytesUsed %d", (int)dir, limit, bytesUsed );
     799    dbgmsg( io, "flushing peer-io, direction %d, limit %zu, bytesUsed %zd", (int)dir, limit, bytesUsed );
    801800    return bytesUsed;
    802801}
  • trunk/libtransmission/peer-io.h

    r7580 r7594  
    349349                               tr_bool        isEnabled );
    350350                       
    351 int       tr_peerIoFlush( tr_peerIo     * io,
     351ssize_t   tr_peerIoFlush( tr_peerIo     * io,
    352352                          tr_direction    dir,
    353353                          size_t          byteLimit );
  • trunk/libtransmission/utils.c

    r7592 r7594  
    226226tr_deepLoggingIsActive( void )
    227227{
    228     static tr_bool deepLoggingIsActive = -1;
    229 
    230     if( deepLoggingIsActive == -1 )
     228    static int8_t deepLoggingIsActive = -1;
     229
     230    if( deepLoggingIsActive < 0 )
    231231        deepLoggingIsActive = IsDebuggerPresent() || (tr_getLog()!=NULL);
    232232
    233     return deepLoggingIsActive;
     233    return deepLoggingIsActive != 0;
    234234}
    235235
Note: See TracChangeset for help on using the changeset viewer.