Changeset 3317 for trunk/libtransmission/tracker.c
- Timestamp:
- Oct 7, 2007, 4:07:19 PM (15 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/libtransmission/tracker.c
r3308 r3317 45 45 #define DEFAULT_ANNOUNCE_INTERVAL_MSEC (MINUTES_TO_MSEC(20)) 46 46 47 /* this is how long we'll leave a scrape request hanging before timeout */ 48 #define SCRAPE_TIMEOUT_INTERVAL_SEC 60 49 50 /* this is how long we'll leave a tracker request hanging before timeout */ 51 #define REQ_TIMEOUT_INTERVAL_SEC 60 47 /* this is how long we'll leave a request hanging before timeout */ 48 #define TIMEOUT_INTERVAL_SEC 5 52 49 53 50 /* the value of the 'numwant' argument passed in tracker requests */ … … 93 90 94 91 tr_timer * scrapeTimer; 95 96 struct evhttp_connection * connection;97 92 } 98 93 Tracker; … … 160 155 ***/ 161 156 157 static int 158 freeConnection( void * evcon ) 159 { 160 evhttp_connection_free( evcon ); 161 return FALSE; 162 } 163 164 static void 165 connectionClosedCB( struct evhttp_connection * evcon, void * handle ) 166 { 167 tr_timerNew( handle, freeConnection, evcon, 100 ); 168 } 169 162 170 static struct evhttp_connection* 163 171 getConnection( Tracker * tracker, const char * address, int port ) 164 172 { 165 if( tracker->connection != NULL ) 166 { 167 char * a = NULL; 168 unsigned short p = 0; 169 evhttp_connection_get_peer( tracker->connection, &a, &p ); 170 171 /* old one matches -- reuse it */ 172 if( a && !strcmp(a,address) && p==port ) 173 return tracker->connection; 174 175 /* old one doesn't match -- throw it away */ 176 evhttp_connection_free( tracker->connection ); 177 tracker->connection = NULL; 178 } 179 180 /* make a new connection */ 181 tracker->connection = evhttp_connection_new( address, port ); 182 return tracker->connection; 173 struct evhttp_connection * c = evhttp_connection_new( address, port ); 174 evhttp_connection_set_timeout( c, TIMEOUT_INTERVAL_SEC ); 175 evhttp_connection_set_closecb( c, connectionClosedCB, tracker->handle ); 176 return c; 183 177 } 184 178 … … 371 365 int i; 372 366 tr_ptrArrayRemoveSorted( getTrackerLookupTable( ), t, trackerCompare ); 373 374 if( t->connection != NULL )375 evhttp_connection_free( t->connection );376 367 377 368 tr_ptrArrayFree( t->torrents, NULL ); … … 685 676 Torrent ** torrents = 686 677 (Torrent**) tr_ptrArrayPeek( t->scrapeQueue, &n ); 687 struct evhttp_connection * evcon = NULL;688 struct evhttp_request *req = NULL;678 struct evhttp_connection * evcon; 679 struct evhttp_request *req; 689 680 690 681 ask_n = n; … … 720 711 address->address, address->port, uri ); 721 712 evcon = getConnection( t, address->address, address->port ); 722 evhttp_connection_set_timeout( evcon, SCRAPE_TIMEOUT_INTERVAL_SEC );723 713 req = evhttp_request_new( onScrapeResponse, t ); 724 714 assert( req ); … … 857 847 858 848 static void 849 onStoppedResponse( struct evhttp_request * req UNUSED, void * handle UNUSED ) 850 { 851 } 852 853 static void 859 854 onTrackerResponse( struct evhttp_request * req, void * vdata ) 860 855 { … … 976 971 const tr_tracker_info * address = getCurrentAddress( t->tracker ); 977 972 char * uri; 978 struct evhttp_connection * evcon = NULL;973 struct evhttp_connection * evcon; 979 974 const tr_torrent * tor; 980 975 … … 1002 997 tr_free( t->lastRequest ); 1003 998 t->lastRequest = tr_strdup( eventName ); 1004 evhttp_connection_set_timeout( evcon, REQ_TIMEOUT_INTERVAL_SEC ); 1005 httpReq = evhttp_request_new( onTrackerResponse, onTrackerResponseDataNew(t) ); 999 if( eventName && !strcmp( eventName, "stopped" ) ) 1000 httpReq = evhttp_request_new( onStoppedResponse, t->tracker->handle ); 1001 else 1002 httpReq = evhttp_request_new( onTrackerResponse, onTrackerResponseDataNew(t) ); 1006 1003 addCommonHeaders( t->tracker, httpReq ); 1007 1004 tr_evhttp_make_request( t->tracker->handle, evcon,
Note: See TracChangeset
for help on using the changeset viewer.