Changeset 3755


Ignore:
Timestamp:
Nov 8, 2007, 4:11:09 AM (15 years ago)
Author:
charles
Message:
  • some work on lessening the way we hammer the router.
  • move strlcpy and strlcat out of their own files and into utils.c
Location:
trunk/libtransmission
Files:
2 deleted
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/libtransmission/Makefile.am

    r3731 r3755  
    2727    ratecontrol.c \
    2828    shared.c \
    29     strlcat.c \
    30     strlcpy.c \
    3129    torrent.c \
    3230    tracker.c \
  • trunk/libtransmission/peer-mgr.c

    r3753 r3755  
    914914    if( !ok || !t || !t->isRunning )
    915915    {
     916        if( t ) {
     917            struct peer_atom * atom = getExistingAtom( t, addr );
     918            if( atom )
     919                ++atom->numFails;
     920        }
     921
    916922        tr_peerIoFree( io );
    917923    }
     
    15841590
    15851591static int
    1586 compareAtomByTime( const void * va, const void * vb )
     1592compareCandidates( const void * va, const void * vb )
    15871593{
    15881594    const struct peer_atom * a = * (const struct peer_atom**) va;
    15891595    const struct peer_atom * b = * (const struct peer_atom**) vb;
    1590     if( a->time < b->time ) return -1;
    1591     if( a->time > b->time ) return 1;
     1596    int i;
     1597
     1598    if(( i = tr_compareUint16( a->numFails, b->numFails )))
     1599        return i;
     1600
     1601    if( a->time != b->time )
     1602        return a->time < b->time ? -1 : 1;
     1603
    15921604    return 0;
    15931605}
     
    16331645        }
    16341646
     1647        /* we're wasting our time trying to connect to this bozo. */
     1648        if( atom->numFails > 10 ) {
     1649            tordbg( t, "RECONNECT peer %d (%s) gives us nothing but failure.",
     1650                    i, tr_peerIoAddrStr(&atom->addr,atom->port) );
     1651            continue;
     1652        }
     1653
    16351654        /* if we used this peer recently, give someone else a turn */
    1636         minWait = 60; /* one minute */
    1637         maxWait = (60 * 10); /* ten minutes */
    1638         wait = atom->numFails * 15; /* add 15 secs to the wait interval for each consecutive failure*/
     1655        minWait = 10; /* ten seconds */
     1656        maxWait = (60 * 20); /* twenty minutes */
     1657        wait = atom->numFails * 30; /* add 15 secs to the wait interval for each consecutive failure*/
    16391658        if( wait < minWait ) wait = minWait;
    16401659        if( wait > maxWait ) wait = maxWait;
     
    16481667    }
    16491668
    1650     qsort( ret, retCount, sizeof(struct peer_atom*), compareAtomByTime );
     1669    qsort( ret, retCount, sizeof(struct peer_atom*), compareCandidates );
    16511670    *setmeSize = retCount;
    16521671    return ret;
  • trunk/libtransmission/utils.c

    r3753 r3755  
    761761#endif
    762762}
     763
     764/***
     765****
     766***/
     767
     768
     769#ifndef HAVE_STRLCPY
     770
     771/*
     772 * Copy src to string dst of size siz.  At most siz-1 characters
     773 * will be copied.  Always NUL terminates (unless siz == 0).
     774 * Returns strlen(src); if retval >= siz, truncation occurred.
     775 */
     776size_t
     777strlcpy(char *dst, const char *src, size_t siz)
     778{
     779        char *d = dst;
     780        const char *s = src;
     781        size_t n = siz;
     782
     783        /* Copy as many bytes as will fit */
     784        if (n != 0) {
     785                while (--n != 0) {
     786                        if ((*d++ = *s++) == '\0')
     787                                break;
     788                }
     789        }
     790
     791        /* Not enough room in dst, add NUL and traverse rest of src */
     792        if (n == 0) {
     793                if (siz != 0)
     794                        *d = '\0';              /* NUL-terminate dst */
     795                while (*s++)
     796                        ;
     797        }
     798
     799        return(s - src - 1);    /* count does not include NUL */
     800}
     801
     802#endif /* HAVE_STRLCPY */
     803
     804
     805#ifndef HAVE_STRLCAT
     806
     807/*
     808 * Appends src to string dst of size siz (unlike strncat, siz is the
     809 * full size of dst, not space left).  At most siz-1 characters
     810 * will be copied.  Always NUL terminates (unless siz <= strlen(dst)).
     811 * Returns strlen(src) + MIN(siz, strlen(initial dst)).
     812 * If retval >= siz, truncation occurred.
     813 */
     814size_t
     815strlcat(char *dst, const char *src, size_t siz)
     816{
     817        char *d = dst;
     818        const char *s = src;
     819        size_t n = siz;
     820        size_t dlen;
     821
     822        /* Find the end of dst and adjust bytes left but don't go past end */
     823        while (n-- != 0 && *d != '\0')
     824                d++;
     825        dlen = d - dst;
     826        n = siz - dlen;
     827
     828        if (n == 0)
     829                return(dlen + strlen(s));
     830        while (*s != '\0') {
     831                if (n != 1) {
     832                        *d++ = *s;
     833                        n--;
     834                }
     835                s++;
     836        }
     837        *d = '\0';
     838
     839        return(dlen + (s - src));       /* count does not include NUL */
     840}
     841
     842#endif /* HAVE_STRLCAT */
Note: See TracChangeset for help on using the changeset viewer.