Changeset 3026


Ignore:
Timestamp:
Sep 10, 2007, 2:21:56 PM (14 years ago)
Author:
charles
Message:

goodbye to the shared-loop thread

Location:
branches/encryption/libtransmission
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • branches/encryption/libtransmission/peer-msgs.c

    r3025 r3026  
    996996        tr_timerFree( &p->pulseTag );
    997997        tr_timerFree( &p->pexTag );
     998        tr_publisherFree( &p->publisher );
    998999        tr_list_free( &p->clientAskedFor );
    9991000        tr_list_free( &p->peerAskedFor );
    1000         tr_publisherFree( &p->publisher );
    10011001        evbuffer_free( p->outMessages );
    10021002        evbuffer_free( p->outBlock );
  • branches/encryption/libtransmission/shared.c

    r3025 r3026  
    3838#include "platform.h"
    3939#include "shared.h"
     40#include "timer.h"
    4041#include "upnp.h"
    4142#include "utils.h"
    4243
    43 /* Maximum number of peers that we keep in our local list */
    44 /* This is an arbitrary number, but it seems to work well */
    45 #define MAX_PEER_COUNT 128
    46 
    4744struct tr_shared
    4845{
    49     tr_handle  * h;
    50     volatile int   die;
    51     tr_thread  * thread;
    52     tr_lock    * lock;
     46    tr_handle    * h;
     47    tr_lock      * lock;
     48    tr_timer_tag   pulseTag;
    5349
    5450    /* Incoming connections */
    55     int          publicPort;
    56     int          bindPort;
    57     int          bindSocket;
     51    int publicPort;
     52    int bindPort;
     53    int bindSocket;
    5854
    5955    /* NAT-PMP/UPnP */
     
    6561 * Local prototypes
    6662 **********************************************************************/
    67 static void SharedLoop( void * );
     63static int SharedLoop( void * );
    6864static void SetPublicPort( tr_shared *, int );
    6965static void AcceptPeers( tr_shared * );
     
    8682    s->natpmp     = tr_natpmpInit();
    8783    s->upnp       = tr_upnpInit();
    88     s->die        = 0;
    89     s->thread     = tr_threadNew( SharedLoop, s, "shared" );
     84    s->pulseTag   = tr_timerNew( h, SharedLoop, s, NULL, 100 );
    9085
    9186    return s;
     
    9994void tr_sharedClose( tr_shared * s )
    10095{
    101     /* Stop the thread */
    102     s->die = 1;
    103     tr_threadJoin( s->thread );
     96    tr_timerFree( &s->pulseTag );
    10497
    10598    if( s->bindSocket > -1 )
     
    111104}
    112105
    113 /***********************************************************************
    114  * tr_sharedLock, tr_sharedUnlock
    115  ***********************************************************************
    116  *
    117  **********************************************************************/
     106/**
     107***
     108**/
     109
    118110void tr_sharedLock( tr_shared * s )
    119111{
     
    181173}
    182174
    183 /***********************************************************************
    184  * tr_sharedGetPublicPort
    185  ***********************************************************************
    186  *
    187  **********************************************************************/
    188175int tr_sharedGetPublicPort( tr_shared * s )
    189176{
     
    248235 * SharedLoop
    249236 **********************************************************************/
    250 static void SharedLoop( void * _s )
    251 {
    252     tr_shared * s = _s;
    253     uint64_t      date1, date2;
    254     int           newPort;
     237static int
     238SharedLoop( void * vs )
     239{
     240    int newPort;
     241    tr_shared * s = vs;
    255242
    256243    tr_sharedLock( s );
    257244
    258     while( !s->die )
    259     {
    260         date1 = tr_date();
    261 
    262         /* NAT-PMP and UPnP pulses */
    263         newPort = -1;
    264         tr_natpmpPulse( s->natpmp, &newPort );
    265         if( 0 < newPort && newPort != s->publicPort )
    266         {
    267             SetPublicPort( s, newPort );
    268         }
    269         tr_upnpPulse( s->upnp );
    270 
    271         /* Handle incoming connections */
    272         AcceptPeers( s );
    273 
    274         /* Wait up to 20 ms */
    275         date2 = tr_date();
    276         if( date2 < date1 + 20 )
    277         {
    278             tr_sharedUnlock( s );
    279             tr_wait( date1 + 20 - date2 );
    280             tr_sharedLock( s );
    281         }
    282     }
     245    /* NAT-PMP and UPnP pulses */
     246    newPort = -1;
     247    tr_natpmpPulse( s->natpmp, &newPort );
     248    if( 0 < newPort && newPort != s->publicPort )
     249        SetPublicPort( s, newPort );
     250    tr_upnpPulse( s->upnp );
     251
     252    /* Handle incoming connections */
     253    AcceptPeers( s );
    283254
    284255    tr_sharedUnlock( s );
     256
     257    return TRUE;
    285258}
    286259
Note: See TracChangeset for help on using the changeset viewer.