summaryrefslogtreecommitdiff
path: root/libavformat/avio.c
diff options
context:
space:
mode:
authorReimar Döffinger <Reimar.Doeffinger@gmx.de>2010-01-24 18:09:46 +0000
committerReimar Döffinger <Reimar.Doeffinger@gmx.de>2010-01-24 18:09:46 +0000
commitf1d2b5728caa39172898043e05e2ade6f224056f (patch)
tree8f19366644093c3b535391e4bd321aae69643763 /libavformat/avio.c
parent0b882b4009c9fbe24020c2fe83b21ee43d0784ea (diff)
Make url_read_complete handle EAGAIN more intelligently.
Only retry 2 - 5 times in quick succession and afterwards sleep a bit to avoid creating high CPU load without any progress. Originally committed as revision 21427 to svn://svn.ffmpeg.org/ffmpeg/trunk
Diffstat (limited to 'libavformat/avio.c')
-rw-r--r--libavformat/avio.c10
1 files changed, 10 insertions, 0 deletions
diff --git a/libavformat/avio.c b/libavformat/avio.c
index 706ba4a610..ca022c8eb1 100644
--- a/libavformat/avio.c
+++ b/libavformat/avio.c
@@ -19,6 +19,9 @@
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
+/* needed for usleep() */
+#define _XOPEN_SOURCE 600
+#include <unistd.h>
#include "libavutil/avstring.h"
#include "libavcodec/opt.h"
#include "os_support.h"
@@ -152,14 +155,21 @@ int url_read(URLContext *h, unsigned char *buf, int size)
int url_read_complete(URLContext *h, unsigned char *buf, int size)
{
int ret, len;
+ int fast_retries = 5;
len = 0;
while (len < size) {
ret = url_read(h, buf+len, size-len);
if (ret == AVERROR(EAGAIN)) {
ret = 0;
+ if (fast_retries)
+ fast_retries--;
+ else
+ usleep(1000);
} else if (ret < 1)
return ret < 0 ? ret : len;
+ if (ret)
+ fast_retries = FFMAX(fast_retries, 2);
len += ret;
}
return len;