rpm-software-management / librepo

A library providing C and Python (libcURL like) API for downloading packages and linux repository metadata in rpm-md format
http://rpm-software-management.github.io/librepo/
GNU Lesser General Public License v2.1
75 stars 91 forks source link

Simplified lr_perform()'s loop to prevent busy wait #144

Closed ydroneaud closed 5 years ago

ydroneaud commented 5 years ago

Calling curl_multi_perform() in a loop is actually busy waiting for data being available on the socket.

The whole logic in lr_perform() can be simplified allowing more efficient processing. The function has to repeatedly do:

1) call curl_multi_perform() for curl to fetch data if needed/available 2) call check_transfer_statuses() to check download status 3) if curl needs more data, wait for the socket to have some

Once there's no need for more data, and there's no other transfer pending, lr_perform() can return TRUE.

The function can be further simplified by

This fixes https://bugzilla.redhat.com/show_bug.cgi?id=1691856

Fixes: 208edbecf3b0 ('Reduce download delays by using still_running correctly.')

jrohel commented 5 years ago

Thank you. Fix with nice simplification.