Changeset 7873


Ignore:
Timestamp:
Feb 11, 2009, 4:07:45 PM (13 years ago)
Author:
charles
Message:

(1.5x libT) backport r7870 and r7866 to the 1.5x branch

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

Legend:

Unmodified
Added
Removed
  • branches/1.5x/libtransmission/crypto.c

    r7863 r7873  
    307307
    308308int
    309 tr_cryptoRandInt( int sup )
    310 {
    311     int r;
    312 
    313     RAND_pseudo_bytes ( (unsigned char *) &r, sizeof r );
    314 
    315     return (int) ( sup * ( abs( r ) / ( INT_MAX + 1.0 ) ) );
     309tr_cryptoRandInt( int upperBound )
     310{
     311    int noise;
     312    int val;
     313
     314    if( RAND_pseudo_bytes ( (unsigned char *) &noise, sizeof noise ) >= 0 )
     315    {
     316        val = abs( noise ) % upperBound;
     317    }
     318    else /* fall back to a weaker implementation... */
     319    {
     320        val = tr_cryptoWeakRandInt( upperBound );
     321    }
     322
     323    assert( val >= 0 );
     324    assert( val < upperBound );
     325    return val;
    316326}
    317327
    318328int
    319 tr_cryptoWeakRandInt( int sup )
     329tr_cryptoWeakRandInt( int upperBound )
    320330{
    321331    static int init = 0;
    322332
    323     assert( sup > 0 );
     333    assert( upperBound > 0 );
    324334
    325335    if( !init )
     
    329339    }
    330340
    331     return rand( ) % sup;
     341    return rand( ) % upperBound;
    332342}
    333343
  • branches/1.5x/libtransmission/web.c

    r7855 r7873  
    282282
    283283            mcode = curl_multi_remove_handle( g->multi, easy );
    284             tr_assert( mcode == CURLM_OK, "curl_multi_socket_action() failed: %d (%s)", mcode, curl_multi_strerror( mcode ) );
     284            tr_assert( mcode == CURLM_OK, "curl_multi_remove_handle() failed: %d (%s)", mcode, curl_multi_strerror( mcode ) );
    285285
    286286            curl_easy_cleanup( easy );
     
    337337   after calling this function */
    338338static void
    339 tr_multi_socket_action( tr_web * g, int fd )
     339tr_multi_perform( tr_web * g )
    340340{
    341341    int closed = FALSE;
     
    347347    /* invoke libcurl's processing */
    348348    do {
    349         mcode = curl_multi_socket_action( g->multi, fd, 0, &g->still_running );
    350         dbgmsg( "event_cb(): fd %d, still_running is %d", fd, g->still_running );
     349        dbgmsg( "calling curl_multi_perform..." );
     350        mcode = curl_multi_perform( g->multi, &g->still_running );
     351        dbgmsg( "done calling curl_multi_perform..." );
    351352    } while( mcode == CURLM_CALL_MULTI_PERFORM );
    352     if( ( mcode == CURLM_BAD_SOCKET ) && ( fd != CURL_SOCKET_TIMEOUT ) )
    353         purgeSockinfo( g, fd );
    354     else {
    355         tr_assert( mcode == CURLM_OK, "curl_multi_socket_action() failed on fd %d: %d (%s)", fd, mcode, curl_multi_strerror( mcode ) );
    356         if( mcode != CURLM_OK )
    357             tr_err( "%s", curl_multi_strerror( mcode ) );
    358     }
     353    tr_assert( mcode == CURLM_OK, "curl_multi_perform() failed: %d (%s)", mcode, curl_multi_strerror( mcode ) );
     354    if( mcode != CURLM_OK )
     355        tr_err( "%s", curl_multi_strerror( mcode ) );
    359356
    360357    remove_finished_tasks( g );
     
    375372/* libevent says that sock is ready to be processed, so wake up libcurl */
    376373static void
    377 event_cb( int fd, short kind UNUSED, void * g )
    378 {
    379     tr_multi_socket_action( g, fd );
     374event_cb( int fd UNUSED, short kind UNUSED, void * g )
     375{
     376    tr_multi_perform( g );
    380377}
    381378
     
    385382{
    386383    dbgmsg( "libevent timer is done" );
    387     tr_multi_socket_action( g, CURL_SOCKET_TIMEOUT );
     384    tr_multi_perform( g );
    388385}
    389386
Note: See TracChangeset for help on using the changeset viewer.