Changeset 7486


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

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

Location:
trunk/libtransmission
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/libtransmission/peer-io.c

    r7476 r7486  
    215215{
    216216    int res;
     217    int e;
    217218    tr_peerIo * io = vio;
    218219
     
    236237    }
    237238
     239    errno = 0;
    238240    res = evbuffer_read( io->inbuf, fd, howmuch );
     241    e = errno;
    239242
    240243    if( res > 0 )
     
    252255            what |= EVBUFFER_EOF;
    253256        else if( res == -1 ) {
    254             if( errno == EAGAIN || errno == EINTR ) {
     257            if( e == EAGAIN || e == EINTR ) {
    255258                tr_peerIoSetEnabled( io, dir, TRUE );
    256259                return;
     
    259262        }
    260263
     264        dbgmsg( io, "event_read_cb got an error. res is %d, what is %hd, errno is %d (%s)", res, what, e, strerror( e ) );
     265
    261266        if( io->gotError != NULL )
    262267            io->gotError( io, what, io->userData );
     
    269274    struct evbuffer * buffer = io->outbuf;
    270275    int n = MIN( EVBUFFER_LENGTH( buffer ), howmuch );
    271 
     276    int e;
     277
     278    errno = 0;
    272279#ifdef WIN32
    273280    n = send(fd, buffer->buffer, n,  0 );
     
    275282    n = write(fd, buffer->buffer, n );
    276283#endif
    277     dbgmsg( io, "wrote %d to peer (%s)", n, (n==-1?strerror(errno):"") );
     284    e = errno;
     285    dbgmsg( io, "wrote %d to peer (%s)", n, (n==-1?strerror(e):"") );
    278286
    279287    if( n == -1 )
     
    290298{
    291299    int res = 0;
     300    int e;
    292301    short what = EVBUFFER_WRITE;
    293302    tr_peerIo * io = vio;
     
    309318    }
    310319
     320    errno = 0;
    311321    res = tr_evbuffer_write( io, fd, howmuch );
     322    e = errno;
     323
    312324    if (res == -1) {
    313325#ifndef WIN32
    314326/*todo. evbuffer uses WriteFile when WIN32 is set. WIN32 system calls do not
    315327 *  *set errno. thus this error checking is not portable*/
    316         if (errno == EAGAIN || errno == EINTR || errno == EINPROGRESS)
     328        if (e == EAGAIN || e == EINTR || e == EINPROGRESS)
    317329            goto reschedule;
    318330        /* error case */
     
    342354
    343355 error:
     356
     357    dbgmsg( io, "event_write_cb got an error. res is %d, what is %hd, errno is %d (%s)", res, what, e, strerror( e ) );
     358
    344359    if( io->gotError != NULL )
    345360        io->gotError( io, what, io->userData );
     
    892907tr_peerIoTryRead( tr_peerIo * io, size_t howmuch )
    893908{
    894     int res;
    895 
    896     assert( tr_isPeerIo( io ) );
    897 
    898     howmuch = tr_bandwidthClamp( io->bandwidth, TR_DOWN, howmuch );
    899 
    900     res = howmuch ? evbuffer_read( io->inbuf, io->socket, howmuch ) : 0;
    901 
    902     dbgmsg( io, "read %d from peer (%s)", res, (res==-1?strerror(errno):"") );
    903 
    904     if( EVBUFFER_LENGTH( io->inbuf ) )
    905         canReadWrapper( io );
    906 
    907     if( ( res <= 0 ) && ( io->gotError ) && ( errno != EAGAIN ) && ( errno != EINTR ) && ( errno != EINPROGRESS ) )
     909    int res = 0;
     910
     911    assert( tr_isPeerIo( io ) );
     912
     913    if(( howmuch = tr_bandwidthClamp( io->bandwidth, TR_DOWN, howmuch )))
    908914    {
    909         short what = EVBUFFER_READ | EVBUFFER_ERROR;
    910         if( res == 0 )
    911             what |= EVBUFFER_EOF;
    912         io->gotError( io, what, io->userData );
     915        int e;
     916        errno = 0;
     917        res = evbuffer_read( io->inbuf, io->socket, howmuch );
     918        e = errno;
     919
     920        dbgmsg( io, "read %d from peer (%s)", res, (res==-1?strerror(e):"") );
     921
     922        if( EVBUFFER_LENGTH( io->inbuf ) )
     923            canReadWrapper( io );
     924
     925        if( ( res <= 0 ) && ( io->gotError ) && ( e != EAGAIN ) && ( e != EINTR ) && ( e != EINPROGRESS ) )
     926        {
     927            short what = EVBUFFER_READ | EVBUFFER_ERROR;
     928            if( res == 0 )
     929                what |= EVBUFFER_EOF;
     930            dbgmsg( io, "tr_peerIoTryRead got an error. res is %d, what is %hd, errno is %d (%s)", res, what, e, strerror( e ) );
     931            io->gotError( io, what, io->userData );
     932        }
    913933    }
    914934
     
    923943    assert( tr_isPeerIo( io ) );
    924944
    925     howmuch = tr_bandwidthClamp( io->bandwidth, TR_UP, howmuch );
    926 
    927     n = tr_evbuffer_write( io, io->socket, (int)howmuch );
    928 
    929     if( n > 0 )
    930         didWriteWrapper( io, n );
    931 
    932     if( ( n < 0 ) && ( io->gotError ) && ( errno != EPIPE ) && ( errno != EAGAIN ) && ( errno != EINTR ) && ( errno != EINPROGRESS ) ) {
    933         short what = EVBUFFER_WRITE | EVBUFFER_ERROR;
    934         io->gotError( io, what, io->userData );
     945    if(( howmuch = tr_bandwidthClamp( io->bandwidth, TR_UP, howmuch )))
     946    {
     947        int e;
     948        errno = 0;
     949        n = tr_evbuffer_write( io, io->socket, (int)howmuch );
     950        e = errno;
     951
     952        if( n > 0 )
     953            didWriteWrapper( io, n );
     954
     955        if( ( n < 0 ) && ( io->gotError ) && ( e != EPIPE ) && ( e != EAGAIN ) && ( e != EINTR ) && ( e != EINPROGRESS ) )
     956        {
     957            const short what = EVBUFFER_WRITE | EVBUFFER_ERROR;
     958            dbgmsg( io, "tr_peerIoTryWrite got an error. res is %d, what is %hd, errno is %d (%s)", n, what, e, strerror( e ) );
     959            io->gotError( io, what, io->userData );
     960        }
    935961    }
    936962
  • trunk/libtransmission/peer-mgr.c

    r7476 r7486  
    914914        atom->myflags |= MYFLAG_BANNED;
    915915        peer->doPurge = 1;
    916         tordbg( t, "banning peer %s",
    917                tr_peerIoAddrStr( &atom->addr, atom->port ) );
     916        tordbg( t, "banning peer %s", tr_peerIoAddrStr( &atom->addr, atom->port ) );
    918917    }
    919918}
     
    11411140                addStrike( t, peer );
    11421141                peer->doPurge = 1;
    1143                 tordbg( t, "setting doPurge because we got an EINVAL error" );
     1142                tordbg( t, "setting %s doPurge flag because we got an EINVAL error", tr_peerIoAddrStr( &peer->addr, peer->port ) );
    11441143            }
    11451144            else if( ( e->err == ERANGE )
     
    11491148                /* some protocol error from the peer */
    11501149                peer->doPurge = 1;
    1151                 tordbg( t, "setting doPurge because we got an ERANGE, EMSGSIZE, or ENOTCONN error" );
     1150                tordbg( t, "setting %s doPurge flag because we got an ERANGE, EMSGSIZE, or ENOTCONN error", tr_peerIoAddrStr( &peer->addr, peer->port ) );
    11521151            }
    11531152            else /* a local error, such as an IO error */
Note: See TracChangeset for help on using the changeset viewer.