/* note: this function can free the tr_web if its 'closing' flag is set and no tasks remain. callers must not reference their g pointer after calling this function */ static void tr_multi_socket_action( tr_web * g, int fd, int mask ) { int closed = FALSE; CURLMcode rc; dbgmsg( "check_run_count: prev_running %d, still_running %d", g->prev_running, g->still_running ); /* invoke libcurl's processing */ do { rc = curl_multi_socket_action( g->multi, fd, mask, &g->still_running ); dbgmsg( "event_cb(): fd %d, mask %d, still_running is %d", fd, mask, g->still_running ); } while( rc == CURLM_CALL_MULTI_PERFORM ); if( rc != CURLM_OK ) tr_err( "%s", curl_multi_strerror( rc ) ); remove_finished_tasks( g ); add_tasks_from_queue( g ); if( !g->still_running ) { stop_timer( g ); if( g->closing ) { web_close( g ); closed = TRUE; } } if( !closed ) restart_timer( g ); }
static void tr_multi_perform( tr_web * g, int fd, int curl_what ) { CURLMcode m; dbgmsg( "check_run_count: %d taskCount", g->taskCount ); /* invoke libcurl's processing */ do m = curl_multi_socket_action( g->multi, fd, curl_what, &g->taskCount ); while( m == CURLM_CALL_MULTI_SOCKET ); remove_finished_tasks( g ); if( g->closing && !g->taskCount ) web_free( g ); else restart_timer( g ); }