Changeset 218


Ignore:
Timestamp:
Apr 8, 2006, 3:10:52 PM (15 years ago)
Author:
titer
Message:

Fixed a couple of bugs introduced in [164]

Location:
trunk/libtransmission
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/libtransmission/net.c

    r164 r218  
    6767    tr_lock_t      lock;
    6868    tr_thread_t    thread;
     69    int            orphan;
    6970};
     71
     72/* Hem, global variable. Initialized from tr_init(). */
     73tr_lock_t gethostbynameLock;
    7074
    7175static void resolveFunc( void * _r )
     
    7579
    7680    tr_lockLock( &r->lock );
     81
    7782    r->addr.s_addr = inet_addr( r->address );
    7883    if( r->addr.s_addr != 0xFFFFFFFF )
    7984    {
     85        /* This was an IP address, no resolving required */
    8086        r->status = TR_RESOLVE_OK;
     87        goto resolveDone;
     88    }
     89
     90    tr_lockLock( &gethostbynameLock );
     91    tr_lockUnlock( &r->lock );
     92    host = gethostbyname( r->address );
     93    tr_lockLock( &r->lock );
     94    if( host )
     95    {
     96        memcpy( &r->addr, host->h_addr, host->h_length );
     97        r->status = TR_RESOLVE_OK;
     98    }
     99    else
     100    {
     101        r->status = TR_RESOLVE_ERROR;
     102    }
     103    tr_lockUnlock( &gethostbynameLock );
     104
     105resolveDone:
     106    if( r->orphan )
     107    {
     108        /* tr_netResolveClose was closed already. Free memory */
    81109        tr_lockUnlock( &r->lock );
    82         return;
    83     }
    84     tr_lockUnlock( &r->lock );
    85 
    86     if( !( host = gethostbyname( r->address ) ) )
    87     {
    88         tr_lockLock( &r->lock );
    89         r->status = TR_RESOLVE_ERROR;
     110        tr_lockClose( &r->lock );
     111        free( r );
     112    }
     113    else
     114    {
    90115        tr_lockUnlock( &r->lock );
    91         return;
    92     }
    93     tr_lockLock( &r->lock );
    94     memcpy( &r->addr, host->h_addr, host->h_length );
    95     r->status = TR_RESOLVE_OK;
    96     tr_lockUnlock( &r->lock );
     116    }
    97117}
    98118
     
    106126    tr_lockInit( &r->lock );
    107127    tr_threadCreate( &r->thread, resolveFunc, r );
     128    r->orphan = 0;
    108129
    109130    return r;
     
    127148void tr_netResolveClose( tr_resolve_t * r )
    128149{
     150    tr_lockLock( &r->lock );
     151    if( r->status == TR_RESOLVE_WAIT )
     152    {
     153        /* Let the thread die */
     154        r->orphan = 1;
     155        tr_lockUnlock( &r->lock );
     156        return;
     157    }
     158    tr_lockUnlock( &r->lock );
     159
     160    /* Clean up */
    129161    tr_threadJoin( &r->thread );
    130162    tr_lockClose( &r->lock );
  • trunk/libtransmission/tracker.c

    r217 r218  
    182182        if( tr_fdSocketWillCreate( tor->fdlimit, 1 ) )
    183183        {
     184            tc->status = TC_STATUS_IDLE;
    184185            return 0;
    185186        }
     
    189190        {
    190191            tr_fdSocketClosed( tor->fdlimit, 1 );
     192            tc->status = TC_STATUS_IDLE;
    191193            return 0;
    192194        }
     
    257259    tr_torrent_t * tor = tc->tor;
    258260
    259     if( tc->status > TC_STATUS_IDLE )
     261    if( tc->status == TC_STATUS_RESOLVE )
     262    {
     263        tr_netResolveClose( tc->resolve );
     264    }
     265    else if( tc->status > TC_STATUS_RESOLVE )
    260266    {
    261267        tr_netClose( tc->socket );
  • trunk/libtransmission/transmission.c

    r217 r218  
    3131static void acceptStop( tr_handle_t * h );
    3232
     33/* Used in tr_netResolve */
     34extern tr_lock_t gethostbynameLock;
     35
    3336/***********************************************************************
    3437 * tr_init
     
    4043    tr_handle_t * h;
    4144    int           i, r;
     45
     46    tr_lockInit( &gethostbynameLock );
    4247
    4348    h = calloc( sizeof( tr_handle_t ), 1 );
     
    534539    tr_rcClose( h->download );
    535540    free( h );
     541
     542    tr_lockClose( &gethostbynameLock );
    536543}
    537544
Note: See TracChangeset for help on using the changeset viewer.