Changeset 9710
- Timestamp:
- Dec 10, 2009, 7:05:21 PM (12 years ago)
- Location:
- trunk/libtransmission
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/libtransmission/announcer.c
r9693 r9710 732 732 { 733 733 return ( announce != NULL ) 734 && ( strstr( announce, "tracker.thepiratebay.org" ) == NULL ) /* dead */ 734 735 && ( ( strstr( announce, "http://" ) == announce ) || 735 736 ( strstr( announce, "https://" ) == announce ) ); -
trunk/libtransmission/web.c
r9704 r9710 28 28 #include "web.h" 29 29 30 static tr_bool31 useCurlMultiSocketAction( void )32 {33 static tr_bool tested = FALSE;34 static tr_bool useMultiSocketAction;35 36 if( !tested )37 {38 #ifdef SYS_DARWIN /* for some reason, curl_multi_socket_action() + libevent39 keeps crashing in event_queue_insert() on OS X 10.5 & 10.6 */40 useMultiSocketAction = FALSE;41 #else42 curl_version_info_data * data = curl_version_info( CURLVERSION_NOW );43 tr_inf( "Using libcurl %s", data->version );44 /* Use curl_multi_socket_action() instead of curl_multi_perform()45 * if libcurl >= 7.18.2. See http://trac.transmissionbt.com/ticket/1844 */46 useMultiSocketAction = data->version_num >= 0x071202;47 #endif48 tested = TRUE;49 }50 51 return useMultiSocketAction;52 }53 54 30 enum 55 31 { 56 32 /* arbitrary number */ 57 DEFAULT_TIMER_MSEC = 250033 DEFAULT_TIMER_MSEC = 1500 58 34 }; 35 36 static void 37 tr_multi_perform( tr_web * g, int fd ); 59 38 60 39 #if 0 … … 84 63 int prev_running; 85 64 int still_running; 86 long timer_ms ;65 long timer_msec; 87 66 CURLM * multi; 88 67 tr_session * session; … … 279 258 else 280 259 tr_err( "%s", curl_multi_strerror( mcode ) ); 260 261 tr_multi_perform( web, CURL_SOCKET_TIMEOUT ); 281 262 } 282 263 } … … 372 353 restart_timer( tr_web * g ) 373 354 { 374 struct timeval interval;375 376 355 assert( tr_amInEventThread( g->session ) ); 377 356 assert( g->session != NULL ); … … 379 358 380 359 stop_timer( g ); 381 dbgmsg( "adding a timeout for %.1f seconds from now", g->timer_ms/1000.0 ); 382 tr_timevalMsec( g->timer_ms, &interval ); 383 evtimer_add( &g->timer_event, &interval ); 360 dbgmsg( "adding a timeout for %.1f seconds from now", g->timer_msec/1000.0 ); 361 tr_timerAddMsec( &g->timer_event, g->timer_msec ); 384 362 } 385 363 … … 412 390 413 391 /* invoke libcurl's processing */ 414 if( useCurlMultiSocketAction( ) ) 415 { 416 do { 417 dbgmsg( "calling curl_multi_socket_action..." ); 418 mcode = curl_multi_socket_action( g->multi, fd, 0, &g->still_running ); 419 fd = CURL_SOCKET_TIMEOUT; 420 dbgmsg( "done calling curl_multi_socket_action..." ); 421 } while( mcode == CURLM_CALL_MULTI_SOCKET ); 422 } 423 else 424 { 425 do { 426 dbgmsg( "calling curl_multi_perform..." ); 427 mcode = curl_multi_perform( g->multi, &g->still_running ); 428 dbgmsg( "done calling curl_multi_perform..." ); 429 } while( mcode == CURLM_CALL_MULTI_PERFORM ); 430 } 392 do { 393 dbgmsg( "calling curl_multi_socket_action..." ); 394 mcode = curl_multi_socket_action( g->multi, fd, 0, &g->still_running ); 395 fd = CURL_SOCKET_TIMEOUT; 396 dbgmsg( "done calling curl_multi_socket_action..." ); 397 } while( mcode == CURLM_CALL_MULTI_SOCKET ); 431 398 tr_assert( mcode == CURLM_OK, "curl_multi_perform() failed: %d (%s)", mcode, curl_multi_strerror( mcode ) ); 432 399 if( mcode != CURLM_OK ) … … 453 420 { 454 421 tr_multi_perform( g, fd ); 455 }456 457 /* libevent says that timer_ms have passed, so wake up libcurl */458 static void459 timer_cb( int socket UNUSED, short action UNUSED, void * g )460 {461 dbgmsg( "libevent timer is done" );462 tr_multi_perform( g, CURL_SOCKET_TIMEOUT );463 422 } 464 423 … … 501 460 } 502 461 462 /* libevent says that timer_msec have passed, so wake up libcurl */ 463 static void 464 libevent_timer_cb( int fd UNUSED, short what UNUSED, void * g ) 465 { 466 dbgmsg( "libevent timer is done" ); 467 tr_multi_perform( g, CURL_SOCKET_TIMEOUT ); 468 } 503 469 504 470 /* libcurl documentation: "If 0, it means you should proceed immediately … … 507 473 * before you call curl_multi_perform() again." */ 508 474 static void 509 multi_timer_cb( CURLM * multi UNUSED, long timer_ms, void * vg )475 multi_timer_cb( CURLM * multi UNUSED, long timer_msec, void * vg ) 510 476 { 511 477 tr_web * g = vg; 512 478 513 if( timer_ms < 1 ) {514 if( timer_ms == 0 ) /* call it immediately */515 timer_cb( 0, 0, g );516 timer_ms = DEFAULT_TIMER_MSEC;517 } 518 519 g->timer_ms = timer_ms;479 if( timer_msec < 1 ) { 480 if( timer_msec == 0 ) /* call it immediately */ 481 libevent_timer_cb( 0, 0, g ); 482 timer_msec = DEFAULT_TIMER_MSEC; 483 } 484 485 g->timer_msec = timer_msec; 520 486 restart_timer( g ); 521 487 } … … 534 500 if( session->web ) 535 501 { 502 struct tr_web_task * task; 536 503 static unsigned long tag = 0; 537 struct tr_web_task * task;538 504 539 505 task = tr_new0( struct tr_web_task, 1 ); … … 560 526 tr_webInit( tr_session * session ) 561 527 { 562 CURLMcode mcode;528 tr_web * web; 563 529 static int curlInited = FALSE; 564 tr_web * web;565 530 566 531 /* call curl_global_init if we haven't done it already. … … 576 541 web->multi = curl_multi_init( ); 577 542 web->session = session; 578 web->timer_ms = DEFAULT_TIMER_MSEC; /* overwritten by multi_timer_cb() */ 579 580 evtimer_set( &web->timer_event, timer_cb, web ); 581 mcode = curl_multi_setopt( web->multi, CURLMOPT_SOCKETDATA, web ); 582 tr_assert( mcode == CURLM_OK, "curl_mutli_setopt() failed: %d (%s)", mcode, curl_multi_strerror( mcode ) ); 583 mcode = curl_multi_setopt( web->multi, CURLMOPT_SOCKETFUNCTION, sock_cb ); 584 tr_assert( mcode == CURLM_OK, "curl_mutli_setopt() failed: %d (%s)", mcode, curl_multi_strerror( mcode ) ); 585 mcode = curl_multi_setopt( web->multi, CURLMOPT_TIMERDATA, web ); 586 tr_assert( mcode == CURLM_OK, "curl_mutli_setopt() failed: %d (%s)", mcode, curl_multi_strerror( mcode ) ); 587 mcode = curl_multi_setopt( web->multi, CURLMOPT_TIMERFUNCTION, multi_timer_cb ); 588 tr_assert( mcode == CURLM_OK, "curl_mutli_setopt() failed: %d (%s)", mcode, curl_multi_strerror( mcode ) ); 543 web->timer_msec = DEFAULT_TIMER_MSEC; /* overwritten by multi_timer_cb() */ 544 545 evtimer_set( &web->timer_event, libevent_timer_cb, web ); 546 curl_multi_setopt( web->multi, CURLMOPT_SOCKETDATA, web ); 547 curl_multi_setopt( web->multi, CURLMOPT_SOCKETFUNCTION, sock_cb ); 548 curl_multi_setopt( web->multi, CURLMOPT_TIMERDATA, web ); 549 curl_multi_setopt( web->multi, CURLMOPT_TIMERFUNCTION, multi_timer_cb ); 589 550 590 551 return web;
Note: See TracChangeset
for help on using the changeset viewer.