示例#1
0
void
tr_bandwidthSetParent( tr_bandwidth  * b,
                       tr_bandwidth  * parent )
{
    assert( tr_isBandwidth( b ) );
    assert( b != parent );

    if( b->parent )
    {
        void * removed;

        assert( tr_isBandwidth( b->parent ) );

        removed = tr_ptrArrayRemoveSorted( &b->parent->children, b, comparePointers );
        assert( removed == b );
        assert( tr_ptrArrayFindSorted( &b->parent->children, b, comparePointers ) == NULL );

        b->parent = NULL;
    }

    if( parent )
    {
        assert( tr_isBandwidth( parent ) );
        assert( parent->parent != b );

        tr_ptrArrayInsertSorted( &parent->children, b, comparePointers );
        assert( tr_ptrArrayFindSorted( &parent->children, b, comparePointers ) == b );
        b->parent = parent;
    }
}
示例#2
0
static struct cache_block *
findBlock (tr_cache           * cache,
           tr_torrent         * torrent,
           tr_piece_index_t     piece,
           uint32_t             offset)
{
  struct cache_block key;
  key.tor = torrent;
  key.block = _tr_block (torrent, piece, offset);
  return tr_ptrArrayFindSorted (&cache->blocks, &key, cache_block_compare);
}
示例#3
0
static tr_dns_result
dns_cache_lookup( struct tr_web_task * task, const char * host, const char ** resolved )
{
    tr_dns_result result = TR_DNS_UNTESTED;

    if( task->session->web != NULL )
    {
        struct dns_cache_item key;
        struct dns_cache_item * item;
        tr_ptrArray * cache = &task->session->web->dns_cache;

        key.host = (char*) host;
        item = tr_ptrArrayFindSorted( cache, &key, dns_cache_compare );

        /* has the ttl expired? */
        if( ( item != NULL ) && ( item->expiration <= tr_time( ) ) )
        {
            dns_cache_clear_entry( cache, host );
            item = NULL;
        }

        if( item != NULL )
        {
            result = item->success ? TR_DNS_OK : TR_DNS_FAIL;

            if( result == TR_DNS_OK )
            {
                *resolved = item->resolved_host;
            
                dbgmsg( "found cached dns entry for \"%s\": %s", host, *resolved );
            }
        }
    }

    return result;
}