Changeset 4ed9c8c


Ignore:
Timestamp:
2010-03-21T15:10:07Z (15 years ago)
Author:
Wilmer van der Gaast <wilmer@…>
Branches:
master
Children:
a81d679
Parents:
2e89256
Message:

Fixed 100% CPU usage bug in dcc.c.

Files:
2 edited

Legend:

Unmodified
Added
Removed
  • dcc.c

    r2e89256 r4ed9c8c  
    294294        if( cond & GAIM_INPUT_READ )
    295295        {
    296                 int bytes_received;
    297296                int ret;
    298297               
    299                 ASSERTSOCKOP( ret = recv( fd, &bytes_received, sizeof( bytes_received ), MSG_PEEK ), "Receiving" );
     298                ASSERTSOCKOP( ret = recv( fd, ( (char*) &df->acked ) + df->acked_len,
     299                        sizeof( df->acked ) - df->acked_len, 0 ), "Receiving" );
    300300
    301301                if( ret == 0 )
    302302                        return dcc_abort( df, "Remote end closed connection" );
    303                        
    304                 if( ret < 4 )
    305                 {
    306                         imcb_log( df->ic, "WARNING: DCC SEND: receiver sent only %d bytes instead of 4, shouldn't happen too often!", ret );
     303               
     304                /* How likely is it that a 32-bit integer gets split accross
     305                   packet boundaries? Chances are rarely 0 so let's be sure. */
     306                if( ( df->acked_len = ( df->acked_len + ret ) % 4 ) > 0 )
    307307                        return TRUE;
    308                 }
    309 
    310                 ASSERTSOCKOP( ret = recv( fd, &bytes_received, sizeof( bytes_received ), 0 ), "Receiving" );
    311                 if( ret != 4 )
    312                         return dcc_abort( df, "MSG_PEEK'ed 4, but can only dequeue %d bytes", ret );
    313 
    314                 bytes_received = ntohl( bytes_received );
     308
     309                df->acked = ntohl( df->acked );
    315310
    316311                /* If any of this is actually happening, the receiver should buy a new IRC client */
    317312
    318                 if ( bytes_received > df->bytes_sent )
    319                         return dcc_abort( df, "Receiver magically received more bytes than sent ( %d > %d ) (BUG at receiver?)", bytes_received, df->bytes_sent );
    320 
    321                 if ( bytes_received < file->bytes_transferred )
    322                         return dcc_abort( df, "Receiver lost bytes? ( has %d, had %d ) (BUG at receiver?)", bytes_received, file->bytes_transferred );
     313                if ( df->acked > df->bytes_sent )
     314                        return dcc_abort( df, "Receiver magically received more bytes than sent ( %d > %d ) (BUG at receiver?)", df->acked, df->bytes_sent );
     315
     316                if ( df->acked < file->bytes_transferred )
     317                        return dcc_abort( df, "Receiver lost bytes? ( has %d, had %d ) (BUG at receiver?)", df->acked, file->bytes_transferred );
    323318               
    324                 file->bytes_transferred = bytes_received;
     319                file->bytes_transferred = df->acked;
    325320       
    326321                if( file->bytes_transferred >= file->file_size ) {
     
    412407                    done )
    413408                {
    414                         int ack, ackret;
    415                         ack = htonl( ft->bytes_transferred = df->bytes_sent );
     409                        guint32 ack = htonl( ft->bytes_transferred = df->bytes_sent );
     410                        int ackret;
    416411
    417412                        ASSERTSOCKOP( ackret = send( fd, &ack, 4, 0 ), "Sending DCC ACK" );
  • dcc.h

    r2e89256 r4ed9c8c  
    7777        size_t bytes_sent;
    7878       
     79        /*
     80         * Handle the wonderful sadly-not-deprecated ACKs.
     81         */
     82        guint32 acked;
     83        int acked_len;
     84       
    7985        /* imc's handle */
    8086        file_transfer_t *ft;
Note: See TracChangeset for help on using the changeset viewer.