Changeset 7487 for branches/1.4x


Ignore:
Timestamp:
Dec 24, 2008, 2:50:09 AM (14 years ago)
Author:
charles
Message:

(1.4x libT) fix connectivity error reported by Stargazer. Also, add more debug statements to track down errors like this in the future

Location:
branches/1.4x/libtransmission
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • branches/1.4x/libtransmission/peer-io.c

    r7459 r7487  
    209209{
    210210    int res;
     211    int e;
    211212    tr_peerIo * io = vio;
    212     const size_t howmuch = tr_bandwidthClamp( io->bandwidth, TR_DOWN, io->session->so_rcvbuf );
     213
     214    /* Limit the input buffer to 256K, so it doesn't grow too large */
     215    size_t howmuch;
    213216    const tr_direction dir = TR_DOWN;
     217    const size_t max = 256 * 1024;
     218    const size_t curlen = EVBUFFER_LENGTH( io->inbuf );
     219
     220    howmuch = curlen >= max ? 0 : max - curlen;
     221    howmuch = tr_bandwidthClamp( io->bandwidth, TR_DOWN, howmuch );
    214222
    215223    assert( tr_isPeerIo( io ) );
     
    223231    }
    224232
     233    errno = 0;
    225234    res = evbuffer_read( io->inbuf, fd, howmuch );
     235    e = errno;
    226236
    227237    if( res > 0 )
     
    239249            what |= EVBUFFER_EOF;
    240250        else if( res == -1 ) {
    241             if( errno == EAGAIN || errno == EINTR ) {
     251            if( e == EAGAIN || e == EINTR ) {
    242252                tr_peerIoSetEnabled( io, dir, TRUE );
    243253                return;
     
    246256        }
    247257
     258        dbgmsg( io, "event_read_cb got an error. res is %d, what is %hd, errno is %d (%s)", res, what, e, strerror( e ) );
     259
    248260        if( io->gotError != NULL )
    249261            io->gotError( io, what, io->userData );
     
    256268    struct evbuffer * buffer = io->outbuf;
    257269    int n = MIN( EVBUFFER_LENGTH( buffer ), howmuch );
    258 
     270    int e;
     271
     272    errno = 0;
    259273#ifdef WIN32
    260274    n = send(fd, buffer->buffer, n,  0 );
     
    262276    n = write(fd, buffer->buffer, n );
    263277#endif
    264     dbgmsg( io, "wrote %d to peer (%s)", n, (n==-1?strerror(errno):"") );
     278    e = errno;
     279    dbgmsg( io, "wrote %d to peer (%s)", n, (n==-1?strerror(e):"") );
    265280
    266281    if( n == -1 )
     
    277292{
    278293    int res = 0;
     294    int e;
    279295    short what = EVBUFFER_WRITE;
    280296    tr_peerIo * io = vio;
     
    286302    dbgmsg( io, "libevent says this peer is ready to write" );
    287303
    288     howmuch = MIN( (size_t)io->session->so_sndbuf, EVBUFFER_LENGTH( io->outbuf ) );
    289     howmuch = tr_bandwidthClamp( io->bandwidth, dir, howmuch );
     304    /* Write as much as possible, since the socket is non-blocking, write() will
     305     * return if it can't write any more data without blocking */
     306    howmuch = tr_bandwidthClamp( io->bandwidth, dir, EVBUFFER_LENGTH( io->outbuf ) );
    290307
    291308    /* if we don't have any bandwidth left, stop writing */
     
    295312    }
    296313
     314    errno = 0;
    297315    res = tr_evbuffer_write( io, fd, howmuch );
     316    e = errno;
     317
    298318    if (res == -1) {
    299319#ifndef WIN32
    300320/*todo. evbuffer uses WriteFile when WIN32 is set. WIN32 system calls do not
    301321 *  *set errno. thus this error checking is not portable*/
    302         if (errno == EAGAIN || errno == EINTR || errno == EINPROGRESS)
     322        if (e == EAGAIN || e == EINTR || e == EINPROGRESS)
    303323            goto reschedule;
    304324        /* error case */
     
    328348
    329349 error:
     350
     351    dbgmsg( io, "event_write_cb got an error. res is %d, what is %hd, errno is %d (%s)", res, what, e, strerror( e ) );
     352
    330353    if( io->gotError != NULL )
    331354        io->gotError( io, what, io->userData );
     
    860883tr_peerIoTryRead( tr_peerIo * io, size_t howmuch )
    861884{
    862     int res;
    863 
    864     assert( tr_isPeerIo( io ) );
    865 
    866     howmuch = tr_bandwidthClamp( io->bandwidth, TR_DOWN, howmuch );
    867 
    868     res = howmuch ? evbuffer_read( io->inbuf, io->socket, howmuch ) : 0;
    869 
    870     dbgmsg( io, "read %d from peer (%s)", res, (res==-1?strerror(errno):"") );
    871 
    872     if( EVBUFFER_LENGTH( io->inbuf ) )
    873         canReadWrapper( io );
    874 
    875     if( ( res <= 0 ) && ( io->gotError ) && ( errno != EAGAIN ) && ( errno != EINTR ) && ( errno != EINPROGRESS ) )
     885    int res = 0;
     886
     887    assert( tr_isPeerIo( io ) );
     888
     889    if(( howmuch = tr_bandwidthClamp( io->bandwidth, TR_DOWN, howmuch )))
    876890    {
    877         short what = EVBUFFER_READ | EVBUFFER_ERROR;
    878         if( res == 0 )
    879             what |= EVBUFFER_EOF;
    880         io->gotError( io, what, io->userData );
     891        int e;
     892        errno = 0;
     893        res = evbuffer_read( io->inbuf, io->socket, howmuch );
     894        e = errno;
     895
     896        dbgmsg( io, "read %d from peer (%s)", res, (res==-1?strerror(e):"") );
     897
     898        if( EVBUFFER_LENGTH( io->inbuf ) )
     899            canReadWrapper( io );
     900
     901        if( ( res <= 0 ) && ( io->gotError ) && ( e != EAGAIN ) && ( e != EINTR ) && ( e != EINPROGRESS ) )
     902        {
     903            short what = EVBUFFER_READ | EVBUFFER_ERROR;
     904            if( res == 0 )
     905                what |= EVBUFFER_EOF;
     906            dbgmsg( io, "tr_peerIoTryRead got an error. res is %d, what is %hd, errno is %d (%s)", res, what, e, strerror( e ) );
     907            io->gotError( io, what, io->userData );
     908        }
    881909    }
    882910
     
    891919    assert( tr_isPeerIo( io ) );
    892920
    893     howmuch = tr_bandwidthClamp( io->bandwidth, TR_UP, howmuch );
    894 
    895     n = tr_evbuffer_write( io, io->socket, (int)howmuch );
    896 
    897     if( n > 0 )
    898         didWriteWrapper( io, n );
    899 
    900     if( ( n < 0 ) && ( io->gotError ) && ( errno != EPIPE ) && ( errno != EAGAIN ) && ( errno != EINTR ) && ( errno != EINPROGRESS ) ) {
    901         short what = EVBUFFER_WRITE | EVBUFFER_ERROR;
    902         io->gotError( io, what, io->userData );
     921    if(( howmuch = tr_bandwidthClamp( io->bandwidth, TR_UP, howmuch )))
     922    {
     923        int e;
     924        errno = 0;
     925        n = tr_evbuffer_write( io, io->socket, (int)howmuch );
     926        e = errno;
     927
     928        if( n > 0 )
     929            didWriteWrapper( io, n );
     930
     931        if( ( n < 0 ) && ( io->gotError ) && ( e != EPIPE ) && ( e != EAGAIN ) && ( e != EINTR ) && ( e != EINPROGRESS ) )
     932        {
     933            const short what = EVBUFFER_WRITE | EVBUFFER_ERROR;
     934            dbgmsg( io, "tr_peerIoTryWrite got an error. res is %d, what is %hd, errno is %d (%s)", n, what, e, strerror( e ) );
     935            io->gotError( io, what, io->userData );
     936        }
    903937    }
    904938
  • branches/1.4x/libtransmission/peer-mgr.c

    r7455 r7487  
    913913        atom->myflags |= MYFLAG_BANNED;
    914914        peer->doPurge = 1;
    915         tordbg( t, "banning peer %s",
    916                tr_peerIoAddrStr( &atom->addr, atom->port ) );
     915        tordbg( t, "banning peer %s", tr_peerIoAddrStr( &atom->addr, atom->port ) );
    917916    }
    918917}
     
    11401139                addStrike( t, peer );
    11411140                peer->doPurge = 1;
    1142                 tordbg( t, "setting doPurge because we got an EINVAL error" );
     1141                tordbg( t, "setting %s doPurge flag because we got an EINVAL error", tr_peerIoAddrStr( &peer->addr, peer->port ) );
    11431142            }
    11441143            else if( ( e->err == ERANGE )
     
    11481147                /* some protocol error from the peer */
    11491148                peer->doPurge = 1;
    1150                 tordbg( t, "setting doPurge because we got an ERANGE, EMSGSIZE, or ENOTCONN error" );
     1149                tordbg( t, "setting %s doPurge flag because we got an ERANGE, EMSGSIZE, or ENOTCONN error", tr_peerIoAddrStr( &peer->addr, peer->port ) );
    11511150            }
    11521151            else /* a local error, such as an IO error */
Note: See TracChangeset for help on using the changeset viewer.