Changeset 3755
- Timestamp:
- Nov 8, 2007, 4:11:09 AM (15 years ago)
- Location:
- trunk/libtransmission
- Files:
-
- 2 deleted
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/libtransmission/Makefile.am
r3731 r3755 27 27 ratecontrol.c \ 28 28 shared.c \ 29 strlcat.c \30 strlcpy.c \31 29 torrent.c \ 32 30 tracker.c \ -
trunk/libtransmission/peer-mgr.c
r3753 r3755 914 914 if( !ok || !t || !t->isRunning ) 915 915 { 916 if( t ) { 917 struct peer_atom * atom = getExistingAtom( t, addr ); 918 if( atom ) 919 ++atom->numFails; 920 } 921 916 922 tr_peerIoFree( io ); 917 923 } … … 1584 1590 1585 1591 static int 1586 compare AtomByTime( const void * va, const void * vb )1592 compareCandidates( const void * va, const void * vb ) 1587 1593 { 1588 1594 const struct peer_atom * a = * (const struct peer_atom**) va; 1589 1595 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 1592 1604 return 0; 1593 1605 } … … 1633 1645 } 1634 1646 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 1635 1654 /* if we used this peer recently, give someone else a turn */ 1636 minWait = 60; /* one minute*/1637 maxWait = (60 * 10); /* tenminutes */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*/ 1639 1658 if( wait < minWait ) wait = minWait; 1640 1659 if( wait > maxWait ) wait = maxWait; … … 1648 1667 } 1649 1668 1650 qsort( ret, retCount, sizeof(struct peer_atom*), compare AtomByTime);1669 qsort( ret, retCount, sizeof(struct peer_atom*), compareCandidates ); 1651 1670 *setmeSize = retCount; 1652 1671 return ret; -
trunk/libtransmission/utils.c
r3753 r3755 761 761 #endif 762 762 } 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 */ 776 size_t 777 strlcpy(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 */ 814 size_t 815 strlcat(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.