Changeset 3859


Ignore:
Timestamp:
Nov 17, 2007, 5:49:30 PM (15 years ago)
Author:
charles
Message:

fix timeout error that caused us to drop connections prematurely

Location:
trunk/libtransmission
Files:
2 edited

Legend:

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

    r3846 r3859  
    5151    int socket;
    5252    int encryptionMode;
     53    int timeout;
    5354    struct bufferevent * bufev;
    5455    uint8_t peerId[20];
     
    131132    c->socket = socket;
    132133    c->isIncoming = isIncoming ? 1 : 0;
     134    c->timeout = IO_TIMEOUT_SECS;
    133135    c->bufev = bufferevent_new( c->socket,
    134136                                canReadWrapper,
     
    136138                                gotErrorWrapper,
    137139                                c );
    138     bufferevent_settimeout( c->bufev, IO_TIMEOUT_SECS, IO_TIMEOUT_SECS );
     140    bufferevent_settimeout( c->bufev, c->timeout, c->timeout );
    139141    bufferevent_enable( c->bufev, EV_READ|EV_WRITE );
    140142    bufferevent_setwatermark( c->bufev, EV_READ, 0, TR_RDBUF );
     
    273275                                     canReadWrapper, NULL, gotErrorWrapper,
    274276                                     io );
    275         bufferevent_settimeout( io->bufev, IO_TIMEOUT_SECS, IO_TIMEOUT_SECS );
     277        bufferevent_settimeout( io->bufev, io->timeout, io->timeout );
    276278        bufferevent_enable( io->bufev, EV_READ|EV_WRITE );
    277279        bufferevent_setwatermark( io->bufev, EV_READ, 0, TR_RDBUF );
     
    286288tr_peerIoSetTimeoutSecs( tr_peerIo * io, int secs )
    287289{
    288     bufferevent_settimeout( io->bufev, secs, secs );
     290    io->timeout = secs;
     291    bufferevent_settimeout( io->bufev, io->timeout, io->timeout );
    289292}
    290293
     
    434437    return io!=NULL && io->encryptionMode==PEER_ENCRYPTION_RC4;
    435438}
     439
     440/**
     441***
     442**/
    436443
    437444void
     
    462469
    463470void
     471tr_peerIoWriteUint8( tr_peerIo        * io,
     472                     struct evbuffer  * outbuf,
     473                     uint8_t            writeme )
     474{
     475    tr_peerIoWriteBytes( io, outbuf, &writeme, sizeof(uint8_t) );
     476}
     477
     478void
    464479tr_peerIoWriteUint16( tr_peerIo        * io,
    465480                      struct evbuffer  * outbuf,
     
    471486
    472487void
    473 tr_peerIoWriteUint8( tr_peerIo        * io,
    474                      struct evbuffer  * outbuf,
    475                      uint8_t            writeme )
    476 {
    477     tr_peerIoWriteBytes( io, outbuf, &writeme, sizeof(uint8_t) );
    478 }
    479 
    480 void
    481488tr_peerIoWriteUint32( tr_peerIo        * io,
    482489                      struct evbuffer  * outbuf,
     
    486493    tr_peerIoWriteBytes( io, outbuf, &tmp, sizeof(uint32_t) );
    487494}
     495
     496/***
     497****
     498***/
    488499
    489500void
     
    512523
    513524void
     525tr_peerIoReadUint8( tr_peerIo         * io,
     526                    struct evbuffer   * inbuf,
     527                    uint8_t           * setme )
     528{
     529    tr_peerIoReadBytes( io, inbuf, setme, sizeof(uint8_t) );
     530}
     531
     532void
    514533tr_peerIoReadUint16( tr_peerIo         * io,
    515534                     struct evbuffer   * inbuf,
     
    522541
    523542void
    524 tr_peerIoReadUint8( tr_peerIo         * io,
    525                     struct evbuffer   * inbuf,
    526                     uint8_t           * setme )
    527 {
    528     tr_peerIoReadBytes( io, inbuf, setme, sizeof(uint8_t) );
    529 }
    530 
    531 void
    532543tr_peerIoReadUint32( tr_peerIo         * io,
    533544                     struct evbuffer   * inbuf,
  • trunk/libtransmission/peer-msgs.c

    r3849 r3859  
    6969
    7070    PEX_INTERVAL            = (60 * 1000), /* msec between calls to sendPex() */
    71     PEER_PULSE_INTERVAL     = (100),       /* msec between calls to pulse() */
     71    PEER_PULSE_INTERVAL     = (250),       /* msec between calls to pulse() */
    7272    RATE_PULSE_INTERVAL     = (333),       /* msec between calls to ratePulse() */
    7373     
     
    889889        msgs->state = AWAITING_BT_ID;
    890890    }
    891 dbgmsg( msgs, "readBtLength: got a length of %d, msgs->state is now %d", (int)len, (int)msgs->state );
    892891
    893892    return READ_AGAIN;
     
    10861085    const size_t startBufLen = EVBUFFER_LENGTH( inbuf );
    10871086
    1088 dbgmsg( msgs, "in readBtMessage" );
    1089 
    10901087    --msglen; // id length
    10911088
    1092     if( inlen < msglen ) {
    1093         dbgmsg( msgs, " too short!!! " );
     1089    if( inlen < msglen )
    10941090        return READ_MORE;
    1095     }
    10961091
    10971092    dbgmsg( msgs, "got BT id %d, len %d, buffer size is %d", (int)id, (int)msglen, (int)inlen );
     
    12311226    }
    12321227
    1233     dbgmsg( msgs, "startBufLen was %d, msglen was %d, current inbuf len is %d", (int)startBufLen, (int)(msglen+1), (int)EVBUFFER_LENGTH(inbuf) );
    1234 
    12351228    assert( msglen + 1 == msgs->incoming.length );
    12361229    assert( EVBUFFER_LENGTH(inbuf) == startBufLen - msglen );
     
    12991292gotBadPiece( tr_peermsgs * msgs, uint32_t pieceIndex )
    13001293{
    1301     const uint32_t byteCount = tr_torPieceCountBytes( msgs->torrent, (int)pieceIndex );
     1294    const uint32_t byteCount =
     1295        tr_torPieceCountBytes( msgs->torrent, (int)pieceIndex );
    13021296    reassignBytesToCorrupt( msgs, byteCount );
    13031297}
     
    13181312
    13191313static int
    1320 clientGotBlock( tr_peermsgs * msgs, const uint8_t * data, const struct peer_request * req )
     1314clientGotBlock( tr_peermsgs                * msgs,
     1315                const uint8_t              * data,
     1316                const struct peer_request  * req )
    13211317{
    13221318    int i;
     
    14091405    struct evbuffer * inbuf = EVBUFFER_INPUT ( evin );
    14101406    const size_t buflen = EVBUFFER_LENGTH( inbuf );
    1411     const size_t inlen = MIN( buflen, getDownloadMax( msgs ) );
    1412 
    1413     if( !inlen )
     1407    const size_t n = MIN( buflen, getDownloadMax( msgs ) );
     1408
     1409    if( !n )
    14141410    {
    14151411        ret = READ_DONE;
     
    14171413    else switch( msgs->state )
    14181414    {
    1419         case AWAITING_BT_LENGTH:  ret = readBtLength ( msgs, inbuf, inlen ); break;
    1420         case AWAITING_BT_ID:      ret = readBtId     ( msgs, inbuf, inlen ); break;
    1421         case AWAITING_BT_MESSAGE: ret = readBtMessage( msgs, inbuf, inlen ); break;
    1422         case AWAITING_BT_PIECE:   ret = readBtPiece  ( msgs, inbuf, inlen ); break;
     1415        case AWAITING_BT_LENGTH:  ret = readBtLength ( msgs, inbuf, n ); break;
     1416        case AWAITING_BT_ID:      ret = readBtId     ( msgs, inbuf, n ); break;
     1417        case AWAITING_BT_MESSAGE: ret = readBtMessage( msgs, inbuf, n ); break;
     1418        case AWAITING_BT_PIECE:   ret = readBtPiece  ( msgs, inbuf, n ); break;
    14231419        default: assert( 0 );
    14241420    }
     
    14421438{
    14431439    /* don't let our outbuffer get too large */
    1444     if( tr_peerIoWriteBytesWaiting( msgs->io ) > 4096 )
    1445         return FALSE;
    1446 
    1447     return TRUE;
     1440    return tr_peerIoWriteBytesWaiting( msgs->io ) < 4096;
    14481441}
    14491442
     
    15571550gotError( struct bufferevent * evbuf UNUSED, short what, void * vmsgs )
    15581551{
    1559     dbgmsg( vmsgs, "libevent got an error! what=%d, errno=%d (%s)",
    1560             (int)what, errno, strerror(errno) );
    1561     fireGotError( vmsgs );
     1552    if( what & EVBUFFER_TIMEOUT )
     1553        dbgmsg( vmsgs, "libevent got a timeout, what=%hd", what );
     1554
     1555    if( what & ( EVBUFFER_EOF | EVBUFFER_ERROR ) ) {
     1556        dbgmsg( vmsgs, "libevent got an error! what=%hd, errno=%d (%s)",
     1557                what, errno, strerror(errno) );
     1558        fireGotError( vmsgs );
     1559    }
    15621560}
    15631561
Note: See TracChangeset for help on using the changeset viewer.