ccollect:0.6.2->0.7.0
[nslu2-linux/optware.git] / sources / ctorrent / tracker.patch
blob4d9a0d49733ddc748f4efbe210b8e2b6dd5b4c39
1 diff -ur ctorrent-1.3.4/ctorrent.cpp new/ctorrent.cpp
2 --- ctorrent-1.3.4/ctorrent.cpp 2005-01-26 00:40:07.747876016 +0000
3 +++ new/ctorrent.cpp 2005-01-25 01:34:16.000000000 +0000
4 @@ -87,9 +87,13 @@
5 Tracker.Initial();
7 signal(SIGPIPE,SIG_IGN);
8 - signal(SIGINT,sigint_catch);
9 + signal(SIGINT,sig_catch);
10 + signal(SIGTERM,sig_catch);
11 Downloader();
13 + if( cfg_cache_size ) BTCONTENT.FlushCache();
14 + if( arg_bitfield_file ) BTCONTENT.pBF->WriteToFile(arg_bitfield_file);
15 + WORLD.CloseAll();
17 exit(0);
19 diff -ur ctorrent-1.3.4/downloader.cpp new/downloader.cpp
20 --- ctorrent-1.3.4/downloader.cpp 2005-01-26 00:40:07.748875864 +0000
21 +++ new/downloader.cpp 2005-01-24 19:29:18.000000000 +0000
22 @@ -30,9 +30,9 @@
23 fd_set rfd;
24 fd_set wfd;
26 - for(;;){
27 + do{
28 time(&now);
29 - if( BTCONTENT.SeedTimeout(&now) ) break;
30 + if( BTCONTENT.SeedTimeout(&now) ) Tracker.SetStoped();
32 FD_ZERO(&rfd); FD_ZERO(&wfd);
33 maxfd = Tracker.IntervalCheck(&now,&rfd, &wfd);
34 @@ -48,5 +48,5 @@
35 if(T_FREE != Tracker.GetStatus()) Tracker.SocketReady(&rfd,&wfd,&nfds);
36 if( nfds ) WORLD.AnyPeerReady(&rfd,&wfd,&nfds);
38 - }/* end for(;;) */
39 + } while(Tracker.GetStatus() != T_FINISHED);
41 diff -ur ctorrent-1.3.4/sigint.cpp new/sigint.cpp
42 --- ctorrent-1.3.4/sigint.cpp 2005-01-26 00:40:07.749875712 +0000
43 +++ new/sigint.cpp 2005-01-26 00:39:48.175851416 +0000
44 @@ -4,17 +4,27 @@
45 #include <signal.h>
47 #include "btcontent.h"
48 +#include "tracker.h"
49 #include "peerlist.h"
50 #include "btconfig.h"
51 +#include "sigint.h"
53 -void sigint_catch(int sig_no)
54 +void sig_catch(int sig_no)
56 - if(SIGINT == sig_no){
57 + if(SIGINT == sig_no || SIGTERM == sig_no){
58 + Tracker.SetStoped();
59 + signal(sig_no,sig_catch2);
60 + }
63 +static void sig_catch2(int sig_no)
65 + if(SIGINT == sig_no || SIGTERM == sig_no){
66 if( cfg_cache_size ) BTCONTENT.FlushCache();
67 if( arg_bitfield_file ) BTCONTENT.pBF->WriteToFile(arg_bitfield_file);
68 WORLD.CloseAll();
69 - signal(SIGINT,SIG_DFL);
70 - raise(SIGINT);
71 + signal(sig_no,SIG_DFL);
72 + raise(sig_no);
76 diff -ur ctorrent-1.3.4/sigint.h new/sigint.h
77 --- ctorrent-1.3.4/sigint.h 2005-01-26 00:40:07.749875712 +0000
78 +++ new/sigint.h 2005-01-25 01:30:11.000000000 +0000
79 @@ -2,7 +2,8 @@
80 #define SIGINT_H
82 #ifndef WINDOWS
83 -void sigint_catch(int sig_no);
84 +void sig_catch(int sig_no);
85 +static void sig_catch2(int sig_no);
86 #endif
88 #endif
89 diff -ur ctorrent-1.3.4/tracker.cpp new/tracker.cpp
90 --- ctorrent-1.3.4/tracker.cpp 2005-01-26 00:40:07.751875408 +0000
91 +++ new/tracker.cpp 2005-01-26 00:38:52.828265528 +0000
92 @@ -31,7 +31,7 @@
93 m_sock = INVALID_SOCKET;
94 m_port = 80;
95 m_status = T_FREE;
96 - m_f_started = m_f_stoped = m_f_pause = 0;
97 + m_f_started = m_f_stoped = m_f_pause = m_f_completed = 0;
98 m_interval = 15;
100 m_connect_refuse_click = 0;
101 @@ -54,7 +54,8 @@
103 m_reponse_buffer.Reset();
104 time(&m_last_timestamp);
105 - m_status = T_FREE;
106 + if (m_f_stoped) m_status = T_FINISHED;
107 + else m_status = T_FREE;
110 int btTracker:: _IPsin(char *h, int p, struct sockaddr_in *psin)
111 @@ -329,14 +332,15 @@
112 // fprintf(stdout,"Old Set Self:");
113 // fprintf(stdout,"%s\n", inet_ntoa(Self.m_sin.sin_addr));
115 - if( m_f_stoped ) /* stopped */
116 - event = str_event[1];
117 - else if( BTCONTENT.pBF->IsFull()) /* download complete */
118 - event = str_event[2];
119 - else if( m_f_started ) /* interval */
120 - event = (char*) 0;
121 - else
122 + if( m_f_stoped )
123 + event = str_event[1]; /* stopped */
124 + else if( m_f_started == 0 )
125 event = str_event[0]; /* started */
126 + else if( BTCONTENT.pBF->IsFull() && !m_f_completed){
127 + event = str_event[2]; /* download complete */
128 + m_f_completed = 1; /* only send download complete once */
129 + } else
130 + event = (char*) 0; /* interval */
132 if(event){
133 if(MAXPATHLEN < snprintf(REQ_BUFFER,MAXPATHLEN,REQ_URL_P2_FMT,
134 @@ -380,8 +390,7 @@
136 /* tracker communication */
137 if( T_FREE == m_status ){
138 - if((*pnow - m_last_timestamp >= m_interval) &&
139 - (cfg_min_peers > WORLD.TotalPeers())){
140 + if(*pnow - m_last_timestamp >= m_interval){
142 if(Connect() < 0){ Reset(15); return -1; }
144 diff -ur ctorrent-1.3.4/tracker.h new/tracker.h
145 --- ctorrent-1.3.4/tracker.h 2005-01-26 00:40:07.752875256 +0000
146 +++ new/tracker.h 2005-01-26 00:38:21.003103688 +0000
147 @@ -21,6 +21,7 @@
148 #define T_FREE 0
149 #define T_CONNECTING 1
150 #define T_READY 2
151 +#define T_FINISHED 3
153 class btTracker
155 @@ -34,9 +35,10 @@
156 unsigned char m_status:2;
157 unsigned char m_f_started:1;
158 unsigned char m_f_stoped:1;
159 + unsigned char m_f_completed:1;
161 unsigned char m_f_pause:1;
162 - unsigned char m_f_reserved:3;
163 + unsigned char m_f_reserved:2;
166 time_t m_interval; // ÓëTrackerͨÐŵÄʱ¼ä¼ä¸ô
167 @@ -66,6 +68,8 @@
168 void SetPause() { m_f_pause = 1; }
169 void ClearPause() { m_f_pause = 0; }
171 + void SetStoped() { Reset(15); m_f_stoped = 1;}
173 int Connect();
174 int SendRequest();
175 int CheckReponse();