Changeset 6921
- Timestamp:
- Oct 17, 2008, 8:57:54 PM (14 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/libtransmission/web.c
r6919 r6921 29 29 #endif 30 30 31 #define DEFAULT_TIMER_MSEC 2000 32 31 33 #define dbgmsg( ... ) tr_deepLog( __FILE__, __LINE__, "web", __VA_ARGS__ ) 32 34 /* #define dbgmsg(...) do { fprintf( stderr, __VA_ARGS__ ); fprintf( stderr, "\n" ); } while( 0 ) */ … … 37 39 int prev_running; 38 40 int still_running; 41 long timer_ms; 39 42 CURLM * multi; 40 43 tr_session * session; 44 tr_list * easy_queue; 41 45 struct event timer_event; 42 tr_list * easy_queue;43 46 }; 44 47 … … 56 59 tr_web_done_func * done_func; 57 60 void * done_func_user_data; 61 long timer_ms; 58 62 }; 59 63 … … 96 100 curl_easy_setopt( easy, CURLOPT_PROXY, session->proxy ); 97 101 curl_easy_setopt( easy, CURLOPT_PROXYPORT, session->proxyPort ); 98 curl_easy_setopt( easy, CURLOPT_PROXYTYPE, getCurlProxyType( session->proxyType ) ); 102 curl_easy_setopt( easy, CURLOPT_PROXYTYPE, 103 getCurlProxyType( session->proxyType ) ); 99 104 curl_easy_setopt( easy, CURLOPT_PROXYAUTH, CURLAUTH_ANY ); 100 105 } 101 106 if( !task->range && session->isProxyAuthEnabled ) { 102 char * str = tr_strdup_printf( "%s:%s", session->proxyUsername, session->proxyPassword ); 107 char * str = tr_strdup_printf( "%s:%s", session->proxyUsername, 108 session->proxyPassword ); 103 109 curl_easy_setopt( easy, CURLOPT_PROXYUSERPWD, str ); 104 110 tr_free( str ); … … 109 115 curl_easy_setopt( easy, CURLOPT_WRITEFUNCTION, writeFunc ); 110 116 curl_easy_setopt( easy, CURLOPT_WRITEDATA, task ); 111 curl_easy_setopt( easy, CURLOPT_USERAGENT, TR_NAME "/" LONG_VERSION_STRING ); 117 curl_easy_setopt( easy, CURLOPT_USERAGENT, 118 TR_NAME "/" LONG_VERSION_STRING ); 112 119 curl_easy_setopt( easy, CURLOPT_SSL_VERIFYHOST, 0 ); 113 120 curl_easy_setopt( easy, CURLOPT_SSL_VERIFYPEER, 0 ); … … 117 124 curl_easy_setopt( easy, CURLOPT_MAXREDIRS, 5 ); 118 125 curl_easy_setopt( easy, CURLOPT_IPRESOLVE, CURL_IPRESOLVE_V4 ); 119 curl_easy_setopt( easy, CURLOPT_VERBOSE, getenv( "TR_CURL_VERBOSE" ) != NULL ); 126 curl_easy_setopt( easy, CURLOPT_VERBOSE, 127 getenv( "TR_CURL_VERBOSE" ) != NULL ); 120 128 if( task->range ) 121 129 curl_easy_setopt( easy, CURLOPT_RANGE, task->range ); 122 else /* don't set encoding if range is sent; it messes up binary data */130 else /* don't set encoding on webseeds; it messes up binary data */ 123 131 curl_easy_setopt( easy, CURLOPT_ENCODING, "" ); 124 132 125 133 if( web->still_running >= MAX_CONCURRENT_TASKS ) { 126 134 tr_list_append( &web->easy_queue, easy ); 127 dbgmsg( " >> adding a task to the curl queue... size is now %d", tr_list_size( web->easy_queue ) ); 135 dbgmsg( " >> adding a task to the curl queue... size is now %d", 136 tr_list_size( web->easy_queue ) ); 128 137 } else { 129 138 CURLMcode rc = curl_multi_add_handle( web->multi, easy ); … … 246 255 } 247 256 257 258 static void 259 reset_timer( tr_web * g ) 260 { 261 struct timeval timeout; 262 263 if( evtimer_pending( &g->timer_event, NULL ) ) 264 evtimer_del( &g->timer_event ); 265 266 dbgmsg( "adding a timeout for %ld seconds from now", g->timer_ms/1000l ); 267 tr_timevalMsec( g->timer_ms, &timeout ); 268 timeout_add( &g->timer_event, &timeout ); 269 } 270 248 271 /* libevent says that sock is ready to be processed, so wake up libcurl */ 249 272 static void … … 273 296 tr_err( "%s", curl_multi_strerror( rc ) ); 274 297 298 reset_timer( g ); 275 299 check_run_count( g ); 276 300 } 277 301 278 /* libevent says that time out_ms have passed, so wake up libcurl */302 /* libevent says that timer_ms have passed, so wake up libcurl */ 279 303 static void 280 304 timer_cb( int socket UNUSED, short action UNUSED, void * vg ) … … 294 318 tr_err( "%s", curl_multi_strerror( rc ) ); 295 319 320 reset_timer( g ); 296 321 check_run_count( g ); 297 322 } … … 359 384 360 385 361 /* libcurl wants us to tell it when timeout_ms have passed */ 362 static void 363 multi_timer_cb( CURLM *multi UNUSED, long timeout_ms, void * vweb ) 364 { 365 tr_web * web = vweb; 366 struct timeval timeout; 367 dbgmsg( "adding a timeout for %ld seconds from now", timeout_ms/1000l ); 368 tr_timevalMsec( timeout_ms, &timeout ); 369 timeout_add( &web->timer_event, &timeout ); 386 /* from libcurl documentation: "The timeout value returned in the long timeout 387 points to, is in number of milliseconds at this very moment. If 0, it means 388 you should proceed immediately without waiting for anything. If it 389 returns -1, there's no timeout at all set. Note: if libcurl returns a -1 390 timeout here, it just means that libcurl currently has no stored timeout 391 value. You must not wait too long (more than a few seconds perhaps) before 392 you call curl_multi_perform() again." */ 393 static void 394 multi_timer_cb( CURLM *multi UNUSED, long timer_ms, void * g ) 395 { 396 if( timer_ms < 1 ) { 397 if( timer_ms == 0 ) /* call it immediately */ 398 timer_cb( 0, 0, g ); 399 timer_ms = DEFAULT_TIMER_MSEC; 400 } 401 reset_timer( g ); 370 402 } 371 403 … … 417 449 web->multi = curl_multi_init( ); 418 450 web->session = session; 451 web->timer_ms = DEFAULT_TIMER_MSEC; /* default value to overwrite in multi_timer_cb() */ 419 452 420 453 timeout_set( &web->timer_event, timer_cb, web );
Note: See TracChangeset
for help on using the changeset viewer.