Ignore:
Timestamp:
Dec 15, 2008, 9:22:11 PM (12 years ago)
Author:
charles
Message:

(1.4x libT) probable fix for the "greedy peer" bug

File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/1.4x/libtransmission/iobuf.c

    r7177 r7403  
    7070    int magicNumber;
    7171
     72    int fd;
     73
    7274    int timeout_read;  /* in seconds */
    7375    int timeout_write; /* in seconds */
     
    8991
    9092static int
    91 tr_evbuffer_write( struct evbuffer *buffer, int fd, size_t maxlen )
    92 {
    93     int n = MIN( EVBUFFER_LENGTH( buffer ), maxlen );
     93tr_evbuffer_write( struct evbuffer *buffer, int fd, size_t howmuch )
     94{
     95    int n = MIN( EVBUFFER_LENGTH( buffer ), howmuch );
    9496
    9597#ifdef WIN32
     
    107109}
    108110
     111int
     112tr_iobuf_flush_output_buffer( struct tr_iobuf * b, size_t howmuch )
     113{
     114    int res;
     115
     116    assert( isBuf( b ) );
     117
     118    howmuch = tr_bandwidthClamp( b->bandwidth, TR_UP, howmuch );
     119    howmuch = MIN( howmuch, EVBUFFER_LENGTH( b->output ) );
     120
     121    res = howmuch ? tr_evbuffer_write( b->output, b->fd, howmuch ) : 0;
     122
     123    if( ( res > 0 ) && ( b->writecb != NULL ) )
     124        (*b->writecb)( b, (size_t)res, b->cbarg );
     125
     126    if( ( res < 0 ) && ( b->errorcb != NULL ) && ( errno != EAGAIN && errno != EINTR && errno != EINPROGRESS ) )
     127        (*b->errorcb)( b, (short)res, b->cbarg );
     128
     129    return res;
     130}
     131
     132int
     133tr_iobuf_tryread( struct tr_iobuf * b, size_t howmuch )
     134{
     135    int res;
     136
     137    assert( isBuf( b ) );
     138
     139    howmuch = tr_bandwidthClamp( b->bandwidth, TR_DOWN, howmuch );
     140
     141    res = howmuch ? evbuffer_read( b->input, b->fd, howmuch ) : 0;
     142
     143    if( ( res > 0 ) && ( b->readcb != NULL ) )
     144        (*b->readcb)( b, (size_t)res, b->cbarg );
     145
     146    if( ( res < 0 ) && ( b->errorcb != NULL ) && ( errno != EAGAIN && errno != EINTR ) )
     147        (*b->errorcb)( b, (short)res, b->cbarg );
     148
     149    return res;
     150}
     151
     152
    109153static int
    110154tr_iobuf_add(struct event *ev, int timeout)
     
    259303    b = tr_new0( struct tr_iobuf, 1 );
    260304    b->magicNumber = MAGIC_NUMBER;
     305    b->fd = fd;
    261306    b->session = session;
    262307    b->bandwidth = bandwidth;
Note: See TracChangeset for help on using the changeset viewer.