mirror of
https://github.com/transmission/transmission
synced 2024-12-26 01:27:28 +00:00
(trunk libT) re-add the curl "easy queue" from 1.4x to queue libcurl tasks to ameliorate complaints of "too many open files"
This commit is contained in:
parent
2e9546d70e
commit
9e9743c6b1
1 changed files with 28 additions and 1 deletions
|
@ -72,6 +72,7 @@ struct tr_web
|
|||
CURLM * multi;
|
||||
tr_session * session;
|
||||
struct event timer_event;
|
||||
tr_list * easy_queue;
|
||||
tr_list * fds;
|
||||
};
|
||||
|
||||
|
@ -214,7 +215,10 @@ addTask( void * vtask )
|
|||
else /* don't set encoding on webseeds; it messes up binary data */
|
||||
curl_easy_setopt( easy, CURLOPT_ENCODING, "" );
|
||||
|
||||
{
|
||||
if( web->still_running >= MAX_CONCURRENT_TASKS ) {
|
||||
tr_list_append( &web->easy_queue, easy );
|
||||
dbgmsg( ">> enqueueing a task... size is now %d", tr_list_size( web->easy_queue ) );
|
||||
} else {
|
||||
const CURLMcode mcode = curl_multi_add_handle( web->multi, easy );
|
||||
tr_assert( mcode == CURLM_OK, "curl_multi_add_handle() failed: %d (%s)", mcode, curl_multi_strerror( mcode ) );
|
||||
if( mcode == CURLM_OK )
|
||||
|
@ -324,6 +328,27 @@ restart_timer( tr_web * g )
|
|||
evtimer_add( &g->timer_event, &interval );
|
||||
}
|
||||
|
||||
static void
|
||||
add_tasks_from_queue( tr_web * g )
|
||||
{
|
||||
while( ( g->still_running < MAX_CONCURRENT_TASKS )
|
||||
&& ( tr_list_size( g->easy_queue ) > 0 ) )
|
||||
{
|
||||
CURL * easy = tr_list_pop_front( &g->easy_queue );
|
||||
if( easy )
|
||||
{
|
||||
const CURLMcode rc = curl_multi_add_handle( g->multi, easy );
|
||||
if( rc != CURLM_OK )
|
||||
tr_err( "%s", curl_multi_strerror( rc ) );
|
||||
else {
|
||||
dbgmsg( "pumped the task queue, %d remain",
|
||||
tr_list_size( g->easy_queue ) );
|
||||
++g->still_running;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
web_close( tr_web * g )
|
||||
{
|
||||
|
@ -372,6 +397,8 @@ tr_multi_perform( tr_web * g, int fd )
|
|||
|
||||
remove_finished_tasks( g );
|
||||
|
||||
add_tasks_from_queue( g );
|
||||
|
||||
if( !g->still_running ) {
|
||||
assert( tr_list_size( g->fds ) == 0 );
|
||||
stop_timer( g );
|
||||
|
|
Loading…
Reference in a new issue