Changeset 1420


Ignore:
Timestamp:
Jan 21, 2007, 7:16:18 AM (15 years ago)
Author:
titer
Message:

Officially give up on making libT reentrant, and simplify our code instead

Location:
trunk/libtransmission
Files:
15 edited

Legend:

Unmodified
Added
Removed
  • trunk/libtransmission/fdlimit.c

    r1408 r1420  
    2929                                connections to trackers */
    3030
     31/***********************************************************************
     32 * Structures
     33 **********************************************************************/
    3134typedef struct tr_openFile_s
    3235{
     
    4346
    4447    uint64_t   date;
    45 
    46 } tr_openFile_t;
    47 
    48 struct tr_fd_s
     48}
     49tr_openFile_t;
     50
     51typedef struct tr_fd_s
    4952{
    5053    tr_lock_t       lock;
     
    5760
    5861    tr_openFile_t   open[TR_MAX_OPEN_FILES];
    59 };
     62}
     63tr_fd_t;
     64
     65static tr_fd_t * gFd = NULL;
    6066
    6167/***********************************************************************
     
    6369 **********************************************************************/
    6470static int  ErrorFromErrno();
    65 static int  OpenFile( tr_fd_t * f, int i, char * folder, char * name,
    66                       int write );
    67 static void CloseFile( tr_fd_t * f, int i );
     71static int  OpenFile( int i, char * folder, char * name, int write );
     72static void CloseFile( int i );
    6873
    6974
     
    7176 * tr_fdInit
    7277 **********************************************************************/
    73 tr_fd_t * tr_fdInit()
    74 {
    75     tr_fd_t * f;
     78void tr_fdInit()
     79{
    7680    int i, j, s[4096];
    7781
    78     f = calloc( sizeof( tr_fd_t ), 1 );
     82    if( gFd )
     83    {
     84        tr_err( "tr_fdInit was called before!" );
     85        return;
     86    }
     87
     88    gFd = calloc( sizeof( tr_fd_t ), 1 );
    7989
    8090    /* Init lock and cond */
    81     tr_lockInit( &f->lock );
    82     tr_condInit( &f->cond );
     91    tr_lockInit( &gFd->lock );
     92    tr_condInit( &gFd->cond );
    8393
    8494    /* Detect the maximum number of open files or sockets */
     
    97107    tr_dbg( "%d usable file descriptors", i );
    98108
    99     f->reserved  = 0;
    100     f->normal    = 0;
    101 
    102     f->normalMax = i - TR_RESERVED_FDS - 10;
     109    gFd->reserved  = 0;
     110    gFd->normal    = 0;
     111
     112    gFd->normalMax = i - TR_RESERVED_FDS - 10;
    103113        /* To be safe, in case the UI needs to write a preferences file
    104114           or something */
     
    106116    for( i = 0; i < TR_MAX_OPEN_FILES; i++ )
    107117    {
    108         f->open[i].status = STATUS_INVALID;
    109     }
    110 
    111     return f;
     118        gFd->open[i].status = STATUS_INVALID;
     119    }
    112120}
    113121
     
    115123 * tr_fdFileOpen
    116124 **********************************************************************/
    117 int tr_fdFileOpen( tr_fd_t * f, char * folder, char * name, int write )
     125int tr_fdFileOpen( char * folder, char * name, int write )
    118126{
    119127    int i, winner, ret;
    120128    uint64_t date;
    121129
    122     tr_lockLock( &f->lock );
     130    tr_lockLock( &gFd->lock );
    123131
    124132    /* Is it already open? */
    125133    for( i = 0; i < TR_MAX_OPEN_FILES; i++ )
    126134    {
    127         if( f->open[i].status & STATUS_INVALID ||
    128             strcmp( folder, f->open[i].folder ) ||
    129             strcmp( name, f->open[i].name ) )
     135        if( gFd->open[i].status & STATUS_INVALID ||
     136            strcmp( folder, gFd->open[i].folder ) ||
     137            strcmp( name, gFd->open[i].name ) )
    130138        {
    131139            continue;
    132140        }
    133         if( f->open[i].status & STATUS_CLOSING )
     141        if( gFd->open[i].status & STATUS_CLOSING )
    134142        {
    135143            /* File is being closed by another thread, wait until
    136144             * it's done before we reopen it */
    137             tr_condWait( &f->cond, &f->lock );
     145            tr_condWait( &gFd->cond, &gFd->lock );
    138146            i = -1;
    139147            continue;
    140148        }
    141         if( f->open[i].write < write )
     149        if( gFd->open[i].write < write )
    142150        {
    143151            /* File is open read-only and needs to be closed then
    144152             * re-opened read-write */
    145             CloseFile( f, i );
     153            CloseFile( i );
    146154            continue;
    147155        }
     
    153161    for( i = 0; i < TR_MAX_OPEN_FILES; i++ )
    154162    {
    155         if( f->open[i].status & STATUS_INVALID )
     163        if( gFd->open[i].status & STATUS_INVALID )
    156164        {
    157165            winner = i;
     
    168176        for( i = 0; i < TR_MAX_OPEN_FILES; i++ )
    169177        {
    170             if( !( f->open[i].status & STATUS_UNUSED ) )
     178            if( !( gFd->open[i].status & STATUS_UNUSED ) )
    171179            {
    172180                continue;
    173181            }
    174             if( f->open[i].date < date )
     182            if( gFd->open[i].date < date )
    175183            {
    176184                winner = i;
    177                 date   = f->open[i].date;
     185                date   = gFd->open[i].date;
    178186            }
    179187        }
     
    181189        if( winner >= 0 )
    182190        {
    183             CloseFile( f, winner );
     191            CloseFile( winner );
    184192            goto open;
    185193        }
    186194
    187195        /* All used! Wait a bit and try again */
    188         tr_condWait( &f->cond, &f->lock );
     196        tr_condWait( &gFd->cond, &gFd->lock );
    189197    }
    190198
    191199open:
    192     if( ( ret = OpenFile( f, winner, folder, name, write ) ) )
    193     {
    194         tr_lockUnlock( &f->lock );
     200    if( ( ret = OpenFile( winner, folder, name, write ) ) )
     201    {
     202        tr_lockUnlock( &gFd->lock );
    195203        return ret;
    196204    }
    197     snprintf( f->open[winner].folder, MAX_PATH_LENGTH, "%s", folder );
    198     snprintf( f->open[winner].name, MAX_PATH_LENGTH, "%s", name );
    199     f->open[winner].write = write;
     205    snprintf( gFd->open[winner].folder, MAX_PATH_LENGTH, "%s", folder );
     206    snprintf( gFd->open[winner].name, MAX_PATH_LENGTH, "%s", name );
     207    gFd->open[winner].write = write;
    200208
    201209done:
    202     f->open[winner].status = STATUS_USED;
    203     f->open[winner].date   = tr_date();
    204     tr_lockUnlock( &f->lock );
     210    gFd->open[winner].status = STATUS_USED;
     211    gFd->open[winner].date   = tr_date();
     212    tr_lockUnlock( &gFd->lock );
    205213   
    206     return f->open[winner].file;
     214    return gFd->open[winner].file;
    207215}
    208216
     
    210218 * tr_fdFileRelease
    211219 **********************************************************************/
    212 void tr_fdFileRelease( tr_fd_t * f, int file )
     220void tr_fdFileRelease( int file )
    213221{
    214222    int i;
    215     tr_lockLock( &f->lock );
     223    tr_lockLock( &gFd->lock );
    216224
    217225    for( i = 0; i < TR_MAX_OPEN_FILES; i++ )
    218226    {
    219         if( f->open[i].file == file )
    220         {
    221             f->open[i].status = STATUS_UNUSED;
     227        if( gFd->open[i].file == file )
     228        {
     229            gFd->open[i].status = STATUS_UNUSED;
    222230            break;
    223231        }
    224232    }
    225233   
    226     tr_condSignal( &f->cond );
    227     tr_lockUnlock( &f->lock );
     234    tr_condSignal( &gFd->cond );
     235    tr_lockUnlock( &gFd->lock );
    228236}
    229237
     
    231239 * tr_fdFileClose
    232240 **********************************************************************/
    233 void tr_fdFileClose( tr_fd_t * f, char * folder, char * name )
     241void tr_fdFileClose( char * folder, char * name )
    234242{
    235243    int i;
    236244
    237     tr_lockLock( &f->lock );
     245    tr_lockLock( &gFd->lock );
    238246
    239247    for( i = 0; i < TR_MAX_OPEN_FILES; i++ )
    240248    {
    241         if( f->open[i].status & STATUS_INVALID )
     249        if( gFd->open[i].status & STATUS_INVALID )
    242250        {
    243251            continue;
    244252        }
    245         if( !strcmp( folder, f->open[i].folder ) &&
    246             !strcmp( name, f->open[i].name ) )
    247         {
    248             CloseFile( f, i );
    249         }
    250     }
    251 
    252     tr_lockUnlock( &f->lock );
     253        if( !strcmp( folder, gFd->open[i].folder ) &&
     254            !strcmp( name, gFd->open[i].name ) )
     255        {
     256            CloseFile( i );
     257        }
     258    }
     259
     260    tr_lockUnlock( &gFd->lock );
    253261}
    254262
     
    256264 * tr_fdSocketWillCreate
    257265 **********************************************************************/
    258 int tr_fdSocketWillCreate( tr_fd_t * f, int reserved )
     266int tr_fdSocketWillCreate( int reserved )
    259267{
    260268    int ret;
    261269
    262     tr_lockLock( &f->lock );
     270    tr_lockLock( &gFd->lock );
    263271
    264272    if( reserved )
    265273    {
    266         if( f->reserved < TR_RESERVED_FDS )
     274        if( gFd->reserved < TR_RESERVED_FDS )
    267275        {
    268276            ret = 0;
    269             (f->reserved)++;
     277            (gFd->reserved)++;
    270278        }
    271279        else
     
    276284    else
    277285    {
    278         if( f->normal < f->normalMax )
     286        if( gFd->normal < gFd->normalMax )
    279287        {
    280288            ret = 0;
    281             (f->normal)++;
     289            (gFd->normal)++;
    282290        }
    283291        else
     
    287295    }
    288296
    289     tr_lockUnlock( &f->lock );
     297    tr_lockUnlock( &gFd->lock );
    290298
    291299    return ret;
     
    295303 * tr_fdSocketClosed
    296304 **********************************************************************/
    297 void tr_fdSocketClosed( tr_fd_t * f, int reserved )
    298 {
    299     tr_lockLock( &f->lock );
     305void tr_fdSocketClosed( int reserved )
     306{
     307    tr_lockLock( &gFd->lock );
    300308
    301309    if( reserved )
    302310    {
    303         (f->reserved)--;
     311        (gFd->reserved)--;
    304312    }
    305313    else
    306314    {
    307         (f->normal)--;
    308     }
    309 
    310     tr_lockUnlock( &f->lock );
     315        (gFd->normal)--;
     316    }
     317
     318    tr_lockUnlock( &gFd->lock );
    311319}
    312320
     
    314322 * tr_fdClose
    315323 **********************************************************************/
    316 void tr_fdClose( tr_fd_t * f )
    317 {
    318     tr_lockClose( &f->lock );
    319     tr_condClose( &f->cond );
    320     free( f );
     324void tr_fdClose()
     325{
     326    tr_lockClose( &gFd->lock );
     327    tr_condClose( &gFd->cond );
     328    free( gFd );
    321329}
    322330
     
    341349 *
    342350 **********************************************************************/
    343 static int OpenFile( tr_fd_t * f, int i, char * folder, char * name,
    344                      int write )
    345 {
    346     tr_openFile_t * file = &f->open[i];
     351static int OpenFile( int i, char * folder, char * name, int write )
     352{
     353    tr_openFile_t * file = &gFd->open[i];
    347354    struct stat sb;
    348355    char * path;
     
    411418 * threads.
    412419 **********************************************************************/
    413 static void CloseFile( tr_fd_t * f, int i )
    414 {
    415     tr_openFile_t * file = &f->open[i];
     420static void CloseFile( int i )
     421{
     422    tr_openFile_t * file = &gFd->open[i];
    416423
    417424    /* If it's already being closed by another thread, just wait till
     
    419426    while( file->status & STATUS_CLOSING )
    420427    {
    421         tr_condWait( &f->cond, &f->lock );
     428        tr_condWait( &gFd->cond, &gFd->lock );
    422429    }
    423430    if( file->status & STATUS_INVALID )
     
    433440    tr_dbg( "Closing %s in %s (%d)", file->name, file->folder, file->write );
    434441    file->status = STATUS_CLOSING;
    435     tr_lockUnlock( &f->lock );
     442    tr_lockUnlock( &gFd->lock );
    436443    close( file->file );
    437     tr_lockLock( &f->lock );
     444    tr_lockLock( &gFd->lock );
    438445    file->status = STATUS_INVALID;
    439     tr_condSignal( &f->cond );
    440 }
    441 
     446    tr_condSignal( &gFd->cond );
     447}
     448
  • trunk/libtransmission/fdlimit.h

    r1356 r1420  
    2323 *****************************************************************************/
    2424
    25 typedef struct tr_fd_s tr_fd_t;
    26 
    2725/***********************************************************************
    2826 * tr_fdInit
     
    3028 * Detect the maximum number of open files and initializes things.
    3129 **********************************************************************/
    32 tr_fd_t * tr_fdInit();
     30void tr_fdInit();
    3331
    3432/***********************************************************************
     
    4240 * one of the TR_ERROR_IO_*.
    4341 **********************************************************************/
    44 int tr_fdFileOpen( tr_fd_t *, char * folder, char * name, int write );
     42int tr_fdFileOpen( char * folder, char * name, int write );
    4543
    4644/***********************************************************************
     
    5048 * moment and can safely be closed.
    5149 **********************************************************************/
    52 void tr_fdFileRelease( tr_fd_t *, int file );
     50void tr_fdFileRelease( int file );
    5351
    5452/***********************************************************************
     
    5856 * flushing data on disk.
    5957 **********************************************************************/
    60 void tr_fdFileClose( tr_fd_t *, char * folder, char * name );
     58void tr_fdFileClose( char * folder, char * name );
    6159
    6260/***********************************************************************
    6361 * tr_fdSocketWillCreate
    64  ***********************************************************************
    65  *
    6662 **********************************************************************/
    67 int tr_fdSocketWillCreate( tr_fd_t *, int );
     63int tr_fdSocketWillCreate( int );
    6864
    6965/***********************************************************************
    7066 * tr_fdSocketClosed
    71  ***********************************************************************
    72  *
    7367 **********************************************************************/
    74 void tr_fdSocketClosed( tr_fd_t *, int );
     68void tr_fdSocketClosed( int );
    7569
    7670
     
    8074 * Frees resources allocated by tr_fdInit.
    8175 **********************************************************************/
    82 void tr_fdClose( tr_fd_t * );
     76void tr_fdClose();
     77
  • trunk/libtransmission/inout.c

    r1419 r1420  
    298298    for( i = 0; i < inf->fileCount; i++ )
    299299    {
    300         tr_fdFileClose( tor->fdlimit, tor->destination,
    301                         inf->files[i].name );
     300        tr_fdFileClose( tor->destination, inf->files[i].name );
    302301    }
    303302}
     
    369368        {
    370369            /* Now let's get a descriptor on the file... */
    371             file = tr_fdFileOpen( tor->fdlimit, tor->destination,
    372                                   inf->files[i].name, isWrite );
     370            file = tr_fdFileOpen( tor->destination, inf->files[i].name,
     371                                  isWrite );
    373372            if( file < 0 )
    374373            {
     
    380379            if( lseek( file, offset, SEEK_SET ) < 0 )
    381380            {
    382                 tr_fdFileRelease( tor->fdlimit, file );
     381                tr_fdFileRelease( file );
    383382                ret = TR_ERROR_IO_OTHER;
    384383                goto cleanup;
     
    388387            if( readOrWrite( file, buf, cur ) != cur )
    389388            {
    390                 tr_fdFileRelease( tor->fdlimit, file );
     389                tr_fdFileRelease( file );
    391390                ret = TR_ERROR_IO_OTHER;
    392391                goto cleanup;
     
    394393
    395394            /* and release the descriptor. */
    396             tr_fdFileRelease( tor->fdlimit, file );
     395            tr_fdFileRelease( file );
    397396        }
    398397
  • trunk/libtransmission/internal.h

    r1419 r1420  
    151151    tr_ratecontrol_t * download;
    152152    tr_ratecontrol_t * swarmspeed;
    153     tr_fd_t          * fdlimit;
    154153
    155154    int               status;
     
    210209    int            uploadLimit;
    211210    int            downloadLimit;
    212     tr_fd_t      * fdlimit;
    213211    tr_shared_t  * shared;
    214212
  • trunk/libtransmission/natpmp.c

    r1356 r1420  
    6565    uint64_t             timeout;
    6666    int                  port;
    67     tr_fd_t *            fdlimit;
    6867    tr_natpmp_uptime_t * uptime;
    6968} tr_natpmp_req_t;
     
    8382    int                newport;
    8483    int                mappedport;
    85     tr_fd_t         *  fdlimit;
    8684    tr_lock_t          lock;
    8785    uint64_t           renew;
     
    9492checktime( tr_natpmp_uptime_t * uptime, uint32_t seen );
    9593static void
    96 killsock( int * fd, tr_fd_t * fdlimit );
     94killsock( int * fd );
    9795static tr_natpmp_req_t *
    98 newreq( int adding, struct in_addr addr, int port, tr_fd_t * fdlimit,
     96newreq( int adding, struct in_addr addr, int port,
    9997        tr_natpmp_uptime_t * uptime );
    10098static tr_tristate_t
    10199pulsereq( tr_natpmp_req_t * req, uint64_t * renew );
    102100static int
    103 mcastsetup( tr_fd_t * fdlimit );
     101mcastsetup();
    104102static void
    105103mcastpulse( tr_natpmp_t * pmp );
     
    113111
    114112tr_natpmp_t *
    115 tr_natpmpInit( tr_fd_t * fdlimit )
     113tr_natpmpInit()
    116114{
    117115    tr_natpmp_t * pmp;
     
    124122
    125123    pmp->state       = PMP_STATE_IDLE;
    126     pmp->fdlimit     = fdlimit;
    127124    pmp->mcastfd     = -1;
    128125
     
    159156        if( 0 > pmp->mcastfd )
    160157        {
    161             pmp->mcastfd = mcastsetup( pmp->fdlimit );
     158            pmp->mcastfd = mcastsetup();
    162159        }
    163160        /* XXX should I change state? */
     
    176173        tr_inf( "stopping nat-pmp" );
    177174        pmp->active = 0;
    178         killsock( &pmp->mcastfd, pmp->fdlimit );
     175        killsock( &pmp->mcastfd );
    179176        switch( pmp->state )
    180177        {
     
    320317                    {
    321318                        pmp->req = newreq( 1, pmp->dest, pmp->newport,
    322                                            pmp->fdlimit, &pmp->uptime );
     319                                           &pmp->uptime );
    323320                        if( NULL == pmp->req )
    324321                        {
     
    373370                    assert( 0 < pmp->mappedport );
    374371                    pmp->req = newreq( 0, pmp->dest, pmp->mappedport,
    375                                        pmp->fdlimit, &pmp->uptime );
     372                                       &pmp->uptime );
    376373                    if( NULL == pmp->req )
    377374                    {
     
    469466
    470467static void
    471 killsock( int * fd, tr_fd_t * fdlimit )
     468killsock( int * fd )
    472469{
    473470    if( 0 <= *fd )
     
    475472        tr_netClose( *fd );
    476473        *fd = -1;
    477         tr_fdSocketClosed( fdlimit, 0 );
     474        tr_fdSocketClosed( 0 );
    478475    }
    479476}
    480477
    481478static tr_natpmp_req_t *
    482 newreq( int adding, struct in_addr addr, int port, tr_fd_t * fdlimit,
     479newreq( int adding, struct in_addr addr, int port,
    483480        tr_natpmp_uptime_t * uptime )
    484481{
     
    492489    }
    493490    ret->fd = -1;
    494     if( tr_fdSocketWillCreate( fdlimit, 0 ) )
     491    if( tr_fdSocketWillCreate( 0 ) )
    495492    {
    496493        goto err;
     
    512509    ret->timeout = now + PMP_TOTAL_DELAY;
    513510    ret->port    = port;
    514     ret->fdlimit = fdlimit;
    515511    ret->uptime  = uptime;
    516512
     
    520516    if( NULL != ret )
    521517    {
    522         killsock( &ret->fd, fdlimit );
     518        killsock( &ret->fd );
    523519    }
    524520    free( ret );
     
    583579
    584580static int
    585 mcastsetup( tr_fd_t * fdlimit )
     581mcastsetup()
    586582{
    587583    int fd;
    588584    struct in_addr addr;
    589585
    590     if( tr_fdSocketWillCreate( fdlimit, 0 ) )
     586    if( tr_fdSocketWillCreate( 0 ) )
    591587    {
    592588        return -1;
     
    597593    if( 0 > fd )
    598594    {
    599         tr_fdSocketClosed( fdlimit, 0 );
     595        tr_fdSocketClosed( 0 );
    600596        return -1;
    601597    }
     
    622618    {
    623619        tr_err( "error reading nat-pmp multicast message" );
    624         killsock( &pmp->mcastfd, pmp->fdlimit );
     620        killsock( &pmp->mcastfd );
    625621        return;
    626622    }
     
    649645    if( NULL != *req )
    650646    {
    651         killsock( &(*req)->fd, (*req)->fdlimit );
     647        killsock( &(*req)->fd );
    652648        free( *req );
    653649        *req = NULL;
  • trunk/libtransmission/natpmp.h

    r920 r1420  
    2828typedef struct tr_natpmp_s tr_natpmp_t;
    2929
    30 tr_natpmp_t * tr_natpmpInit( tr_fd_t * );
     30tr_natpmp_t * tr_natpmpInit();
    3131void        tr_natpmpStart( tr_natpmp_t * );
    3232void        tr_natpmpStop( tr_natpmp_t * );
  • trunk/libtransmission/net.c

    r1401 r1420  
    4242}
    4343
    44 /* TODO: Make this code reentrant */
    4544static tr_thread_t  resolveThread;
    4645static tr_lock_t    resolveLock;
  • trunk/libtransmission/peer.c

    r1419 r1420  
    186186    {
    187187        tr_netClose( peer->socket );
    188         if( tor )
    189            tr_fdSocketClosed( tor->fdlimit, 0 ); /* XXX */
     188        tr_fdSocketClosed( 0 );
    190189    }
    191190    tr_rcClose( peer->download );
  • trunk/libtransmission/peerutils.h

    r1419 r1420  
    9898    /* Connect */
    9999    if( ( peer->status & PEER_STATUS_IDLE ) &&
    100         !tr_fdSocketWillCreate( tor->fdlimit, 0 ) )
     100        !tr_fdSocketWillCreate( 0 ) )
    101101    {
    102102        peer->socket = tr_netOpenTCP( peer->addr, peer->port );
     
    104104        {
    105105            peer_dbg( "connection failed" );
    106             tr_fdSocketClosed( tor->fdlimit, 0 );
     106            tr_fdSocketClosed( 0 );
    107107            return TR_ERROR;
    108108        }
  • trunk/libtransmission/shared.c

    r1419 r1420  
    7373    s->bindPort = -1;
    7474    s->bindSocket = -1;
    75     s->natpmp = tr_natpmpInit( h->fdlimit );
    76     s->upnp = tr_upnpInit( h->fdlimit );
     75    s->natpmp = tr_natpmpInit();
     76    s->upnp = tr_upnpInit();
    7777    s->choking = tr_chokingInit( h );
    7878
     
    9191void tr_sharedClose( tr_shared_t * s )
    9292{
    93     tr_handle_t * h = s->h;
    9493    int ii;
    9594
     
    106105    {
    107106        tr_netClose( s->bindSocket );
    108         tr_fdSocketClosed( h->fdlimit, 0 );
     107        tr_fdSocketClosed( 0 );
    109108    }
    110109    tr_lockClose( &s->lock );
     
    158157    {
    159158        tr_netClose( s->bindSocket );
    160         tr_fdSocketClosed( h->fdlimit, 0 );
     159        tr_fdSocketClosed( 0 );
    161160    }
    162161
    163162    /* Create the new one */
    164     if( !tr_fdSocketWillCreate( h->fdlimit, 0 ) )
     163    if( !tr_fdSocketWillCreate( 0 ) )
    165164    {
    166165        /* XXX should handle failure here in a better way */
     
    168167        if( 0 > s->bindSocket )
    169168        {
    170             tr_fdSocketClosed( h->fdlimit, 0 );
     169            tr_fdSocketClosed( 0 );
    171170        }
    172171        else
     
    307306static void AcceptPeers( tr_shared_t * s )
    308307{
    309     tr_handle_t * h = s->h;
    310308    int socket;
    311309    in_port_t port;
     
    315313    {
    316314        if( s->bindSocket < 0 || s->peerCount >= MAX_PEER_COUNT ||
    317             tr_fdSocketWillCreate( h->fdlimit, 0 ) )
     315            tr_fdSocketWillCreate( 0 ) )
    318316        {
    319317            break;;
     
    323321        if( socket < 0 )
    324322        {
    325             tr_fdSocketClosed( h->fdlimit, 0 );
     323            tr_fdSocketClosed( 0 );
    326324            break;
    327325        }
  • trunk/libtransmission/torrent.c

    r1419 r1420  
    133133    tr_condInit( &tor->cond );
    134134
    135     tor->fdlimit        = h->fdlimit;
    136135    tor->upload         = tr_rcInit();
    137136    tor->download       = tr_rcInit();
  • trunk/libtransmission/tracker.c

    r1417 r1420  
    9898                                      int * peerCount, uint8_t ** peerCompact );
    9999static void        readScrapeAnswer ( tr_tracker_t * tc, const char *, int );
    100 static void        killHttp         ( tr_http_t ** http, tr_fd_t * fdlimit );
     100static void        killHttp         ( tr_http_t ** http );
    101101
    102102tr_tracker_t * tr_trackerInit( tr_torrent_t * tor )
     
    346346        tc->randOffset = tr_rand( 60000 );
    347347       
    348         if( tr_fdSocketWillCreate( tor->fdlimit, 1 ) )
     348        if( tr_fdSocketWillCreate( 1 ) )
    349349        {
    350350            return;
     
    443443
    444444            case TR_NET_ERROR:
    445                 killHttp( &tc->http, tor->fdlimit );
     445                killHttp( &tc->http );
    446446                tc->dateTry = tr_date();
    447447               
     
    453453            case TR_NET_OK:
    454454                readAnswer( tc, data, len, peerCount, peerCompact );
    455                 killHttp( &tc->http, tor->fdlimit );
     455                killHttp( &tc->http );
    456456                break;
    457457        }
     
    460460    if( ( NULL == tc->httpScrape ) && shouldScrape( tc ) )
    461461    {
    462         if( tr_fdSocketWillCreate( tor->fdlimit, 1 ) )
     462        if( tr_fdSocketWillCreate( 1 ) )
    463463        {
    464464            return;
     
    497497
    498498            case TR_NET_ERROR:
    499                 killHttp( &tc->httpScrape, tor->fdlimit );
     499                killHttp( &tc->httpScrape );
    500500                tc->lastScrapeFailed = 1;
    501501                break;
     
    503503            case TR_NET_OK:
    504504                readScrapeAnswer( tc, data, len );
    505                 killHttp( &tc->httpScrape, tor->fdlimit );
     505                killHttp( &tc->httpScrape );
    506506                break;
    507507        }
     
    520520void tr_trackerStopped( tr_tracker_t * tc )
    521521{
    522     tr_torrent_t * tor = tc->tor;
    523 
    524522    /* If we are already sending a query at the moment, we need to
    525523       reconnect */
    526     killHttp( &tc->http, tor->fdlimit );
     524    killHttp( &tc->http );
    527525
    528526    tc->started   = 0;
     
    541539    int ii;
    542540
    543     killHttp( &tc->http, tor->fdlimit );
    544     killHttp( &tc->httpScrape, tor->fdlimit );
     541    killHttp( &tc->http );
     542    killHttp( &tc->httpScrape );
    545543
    546544    for( ii = 0; ii < inf->trackerTiers; ii++ )
     
    11631161}
    11641162
    1165 static void killHttp( tr_http_t ** http, tr_fd_t * fdlimit )
     1163static void killHttp( tr_http_t ** http )
    11661164{
    11671165    if( NULL != *http )
    11681166    {
    11691167        tr_httpClose( *http );
    1170         tr_fdSocketClosed( fdlimit, 1 );
     1168        tr_fdSocketClosed( 1 );
    11711169        *http = NULL;
    11721170    }
  • trunk/libtransmission/transmission.c

    r1405 r1420  
    6565    h->downloadLimit = -1;
    6666   
    67     h->fdlimit = tr_fdInit();
     67    tr_fdInit();
    6868    h->shared = tr_sharedInit( h );
    6969
     
    138138{
    139139    tr_sharedClose( h->shared );
    140     tr_fdClose( h->fdlimit );
     140    tr_fdClose();
    141141    free( h );
    142142
  • trunk/libtransmission/upnp.c

    r1356 r1420  
    9191    unsigned int       discovering : 1;
    9292    tr_upnp_device_t * devices;
    93     tr_fd_t          * fdlimit;
    9493    tr_lock_t          lock;
    9594};
    9695
    9796static int
    98 sendSSDP( tr_fd_t * fdlimit, int fd );
    99 static int
    100 mcastStart( tr_fd_t * fdlimit );
     97sendSSDP( int fd );
     98static int
     99mcastStart();
    101100static void
    102 killSock( tr_fd_t * fdlimit, int * sock );
     101killSock( int * sock );
    103102static void
    104 killHttp( tr_fd_t * fdlimit, tr_http_t ** http );
     103killHttp( tr_http_t ** http );
    105104static int
    106105watchSSDP( tr_upnp_device_t ** devices, int fd );
     
    113112           const char * url, int urlLen );
    114113static void
    115 deviceRemove( tr_upnp_device_t ** prevptr, tr_fd_t * fdlimit );
     114deviceRemove( tr_upnp_device_t ** prevptr );
    116115static int
    117116deviceStop( tr_upnp_device_t * dev );
    118117static int
    119 devicePulse( tr_upnp_device_t * dev, tr_fd_t * fdlimit, int port );
    120 static int
    121 devicePulseHttp( tr_upnp_device_t * dev, tr_fd_t * fdlimit,
     118devicePulse( tr_upnp_device_t * dev, int port );
     119static int
     120devicePulseHttp( tr_upnp_device_t * dev,
    122121                 const char ** body, int * len );
    123122static tr_http_t *
    124 devicePulseGetHttp( tr_upnp_device_t * dev, tr_fd_t * fdlimit );
     123devicePulseGetHttp( tr_upnp_device_t * dev );
    125124static int
    126125parseRoot( const char *buf, int len, char ** soap, char ** scpd );
     
    156155
    157156tr_upnp_t *
    158 tr_upnpInit( tr_fd_t * fdlimit )
     157tr_upnpInit()
    159158{
    160159    tr_upnp_t * upnp;
     
    168167    upnp->infd     = -1;
    169168    upnp->outfd    = -1;
    170     upnp->fdlimit  = fdlimit;
    171169
    172170    tr_lockInit( &upnp->lock );
     
    185183        upnp->active = 1;
    186184        upnp->discovering = 1;
    187         upnp->infd = mcastStart( upnp->fdlimit );
     185        upnp->infd = mcastStart();
    188186        upnp->lastdiscover = 0;
    189187        upnp->lastdelay = SSDP_FIRST_DELAY / 2;
     
    202200        tr_inf( "stopping upnp" );
    203201        upnp->active = 0;
    204         killSock( upnp->fdlimit, &upnp->infd );
    205         killSock( upnp->fdlimit, &upnp->outfd );
     202        killSock( &upnp->infd );
     203        killSock( &upnp->outfd );
    206204    }
    207205
     
    265263    while( NULL != upnp->devices )
    266264    {
    267         deviceRemove( &upnp->devices, upnp->fdlimit );
     265        deviceRemove( &upnp->devices );
    268266    }
    269267
     
    285283        for( ii = &upnp->devices; NULL != *ii; ii = &(*ii)->next )
    286284        {
    287             if( devicePulse( *ii, upnp->fdlimit, upnp->port ) )
     285            if( devicePulse( *ii, upnp->port ) )
    288286            {
    289287                upnp->discovering = 0;
     
    295293            upnp->lastdelay + upnp->lastdiscover < tr_date() )
    296294        {
    297             upnp->outfd = sendSSDP( upnp->fdlimit, upnp->outfd );
     295            upnp->outfd = sendSSDP( upnp->outfd );
    298296            upnp->lastdiscover = tr_date();
    299297            upnp->lastdelay = MIN( upnp->lastdelay * 2, SSDP_MAX_DELAY );
     
    304302        if( watchSSDP( &upnp->devices, upnp->outfd ) )
    305303        {
    306             killSock( upnp->fdlimit, &upnp->outfd );
     304            killSock( &upnp->outfd );
    307305        }
    308306    }
     
    315313            if( deviceStop( *ii ) )
    316314            {
    317                 deviceRemove( ii, upnp->fdlimit );
     315                deviceRemove( ii );
    318316            }
    319317            else
    320318            {
    321                 devicePulse( *ii, upnp->fdlimit, 0 );
     319                devicePulse( *ii, 0 );
    322320                ii = &(*ii)->next;
    323321            }
     
    329327
    330328static int
    331 sendSSDP( tr_fd_t * fdlimit, int fd )
     329sendSSDP( int fd )
    332330{
    333331    char buf[102];
     
    337335    if( 0 > fd )
    338336    {
    339         if( tr_fdSocketWillCreate( fdlimit, 0 ) )
     337        if( tr_fdSocketWillCreate( 0 ) )
    340338        {
    341339            return -1;
     
    344342        if( 0 > fd )
    345343        {
    346             tr_fdSocketClosed( fdlimit, 0 );
     344            tr_fdSocketClosed( 0 );
    347345            return -1;
    348346        }
     
    376374                    strerror( errno ) );
    377375        }
    378         killSock( fdlimit, &fd );
     376        killSock( &fd );
    379377        return -1;
    380378    }
     
    384382
    385383static int
    386 mcastStart( tr_fd_t * fdlimit )
     384mcastStart()
    387385{
    388386    int fd;
    389387    struct in_addr addr;
    390388
    391     if( tr_fdSocketWillCreate( fdlimit, 0 ) )
     389    if( tr_fdSocketWillCreate( 0 ) )
    392390    {
    393391        return -1;
     
    398396    if( 0 > fd )
    399397    {
    400         tr_fdSocketClosed( fdlimit, 0 );
     398        tr_fdSocketClosed( 0 );
    401399        return -1;
    402400    }
     
    406404
    407405static void
    408 killSock( tr_fd_t * fdlimit, int * sock )
     406killSock( int * sock )
    409407{
    410408    if( 0 <= *sock )
     
    412410        tr_netClose( *sock );
    413411        *sock = -1;
    414         tr_fdSocketClosed( fdlimit, 0 );
     412        tr_fdSocketClosed( 0 );
    415413    }
    416414}
    417415
    418416static void
    419 killHttp( tr_fd_t * fdlimit, tr_http_t ** http )
     417killHttp( tr_http_t ** http )
    420418{
    421419    tr_httpClose( *http );
    422420    *http = NULL;
    423     tr_fdSocketClosed( fdlimit, 0 );
     421    tr_fdSocketClosed( 0 );
    424422}
    425423
     
    591589
    592590static void
    593 deviceRemove( tr_upnp_device_t ** prevptr, tr_fd_t * fdlimit )
     591deviceRemove( tr_upnp_device_t ** prevptr )
    594592{
    595593    tr_upnp_device_t * dead;
     
    608606    if( NULL != dead->http )
    609607    {
    610         killHttp( fdlimit, &dead->http );
     608        killHttp( &dead->http );
    611609    }
    612610    actionFree( &dead->getcmd );
     
    635633
    636634static int
    637 devicePulse( tr_upnp_device_t * dev, tr_fd_t * fdlimit, int port )
     635devicePulse( tr_upnp_device_t * dev, int port )
    638636{
    639637    const char * body;
     
    676674    body = NULL;
    677675
    678     code = devicePulseHttp( dev, fdlimit, &body, &len );
     676    code = devicePulseHttp( dev, &body, &len );
    679677    if( 0 > code )
    680678    {
     
    688686        dev->state = UPNPDEV_STATE_ERROR;
    689687        dev->looping = 0;
    690         killHttp( fdlimit, &dev->http );
     688        killHttp( &dev->http );
    691689        return 1;
    692690    }
     
    822820
    823821    dev->lastrequest = tr_date();
    824     killHttp( fdlimit, &dev->http );
     822    killHttp( &dev->http );
    825823
    826824    if( UPNPDEV_STATE_ERROR == dev->state )
     
    848846
    849847static tr_http_t *
    850 devicePulseGetHttp( tr_upnp_device_t * dev, tr_fd_t * fdlimit )
     848devicePulseGetHttp( tr_upnp_device_t * dev )
    851849{
    852850    tr_http_t  * ret;
    853851    char numstr[6];
    854852
    855     if( tr_fdSocketWillCreate( fdlimit, 0 ) )
     853    if( tr_fdSocketWillCreate( 0 ) )
    856854    {
    857855        return NULL;
     
    918916    if( NULL == ret )
    919917    {
    920         tr_fdSocketClosed( fdlimit, 0 );
     918        tr_fdSocketClosed( 0 );
    921919    }
    922920
     
    925923
    926924static int
    927 devicePulseHttp( tr_upnp_device_t * dev, tr_fd_t * fdlimit,
     925devicePulseHttp( tr_upnp_device_t * dev,
    928926                 const char ** body, int * len )
    929927{
     
    938936        }
    939937        dev->lastrequest = tr_date();
    940         dev->http = devicePulseGetHttp( dev, fdlimit );
     938        dev->http = devicePulseGetHttp( dev );
    941939        if( NULL == dev->http )
    942940        {
     
    961959            {
    962960                dev->soapretry = 1;
    963                 killHttp( fdlimit, &dev->http );
     961                killHttp( &dev->http );
    964962                break;
    965963            }
     
    969967            return code;
    970968        case TR_NET_ERROR:
    971             killHttp( fdlimit, &dev->http );
     969            killHttp( &dev->http );
    972970            if( dev->soapretry )
    973971            {
  • trunk/libtransmission/upnp.h

    r920 r1420  
    2828typedef struct tr_upnp_s tr_upnp_t;
    2929
    30 tr_upnp_t * tr_upnpInit( tr_fd_t * );
     30tr_upnp_t * tr_upnpInit();
    3131void        tr_upnpStart( tr_upnp_t * );
    3232void        tr_upnpStop( tr_upnp_t * );
Note: See TracChangeset for help on using the changeset viewer.