[FFmpeg-devel] [RFC] url_write()
Michael Niedermayer
michaelni
Wed Oct 6 00:24:44 CEST 2010
On Tue, Oct 05, 2010 at 11:43:13PM +0200, Reimar D?ffinger wrote:
> On Tue, Oct 05, 2010 at 10:04:43PM +0200, Michael Niedermayer wrote:
> > int url_write(URLContext *h, const unsigned char *buf, int size)
> > {
> > - int ret;
> > + int len= 0;
> > + int fast_retries= 5;
> > if (!(h->flags & (URL_WRONLY | URL_RDWR)))
> > return AVERROR(EIO);
> > /* avoid sending too big packets */
> > if (h->max_packet_size && size > h->max_packet_size)
> > return AVERROR(EIO);
> > - ret = h->prot->url_write(h, buf, size);
> > - return ret;
> > +
> > + while(len<size){
> > + int ret= h->prot->url_write(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;
>
> Very strange space-placement, particularly since the
> "url_read_complete" does not have it.
> Obviously due to some clean up, but I guess both should be
> identical.
its because i copy and pasted part and wrote part by hand then removed
the fast_retries and then decided to put it back
> How about a
> static inline int retry_transfer_wrapper(URLContext *h, const unsigned char *buf, int size,
> int (*transfer_func)(URLContext *h, const unsigned char *buf, int size))
>
> And using it for both instead of duplicating it?
will commit below soon if you are ok with it
commit 39f392b6de49d3135364b5ce119c7453549bb6f5
Author: Michael Niedermayer <michaelni at gmx.at>
Date: Wed Oct 6 00:21:20 2010 +0200
Use retry_transfer_wrapper() in url_write() as its callers do not expect it to stop in the middle.
diff --git a/libavformat/avio.c b/libavformat/avio.c
index bf0d9d8..2dae492 100644
--- a/libavformat/avio.c
+++ b/libavformat/avio.c
@@ -252,8 +252,8 @@ int url_write(URLContext *h, const unsigned char *buf, int size)
/* avoid sending too big packets */
if (h->max_packet_size && size > h->max_packet_size)
return AVERROR(EIO);
- ret = h->prot->url_write(h, buf, size);
- return ret;
+
+ return retry_transfer_wrapper(h, buf, size, h->prot->url_write);
}
int64_t url_seek(URLContext *h, int64_t pos, int whence)
commit 1a617a6b38e742ed1cb77dbe1128f375ee1af4ba
Author: Michael Niedermayer <michaelni at gmx.at>
Date: Wed Oct 6 00:18:34 2010 +0200
Factor retry_transfer_wrapper() out of url_read_complete()
diff --git a/libavformat/avio.c b/libavformat/avio.c
index 4399878..bf0d9d8 100644
--- a/libavformat/avio.c
+++ b/libavformat/avio.c
@@ -215,14 +215,15 @@ int url_read(URLContext *h, unsigned char *buf, int size)
return ret;
}
-int url_read_complete(URLContext *h, unsigned char *buf, int size)
+static inline int retry_transfer_wrapper(URLContext *h, unsigned char *buf, int size,
+ int (*transfer_func)(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);
+ ret = transfer_func(h, buf+len, size-len);
if (ret == AVERROR(EAGAIN)) {
ret = 0;
if (fast_retries)
@@ -238,6 +239,11 @@ int url_read_complete(URLContext *h, unsigned char *buf, int size)
return len;
}
+int url_read_complete(URLContext *h, unsigned char *buf, int size)
+{
+ return retry_transfer_wrapper(h, buf, size, url_read);
+}
+
int url_write(URLContext *h, const unsigned char *buf, int size)
{
int ret;
[...]
--
Michael GnuPG fingerprint: 9FF2128B147EF6730BADF133611EC787040B0FAB
Why not whip the teacher when the pupil misbehaves? -- Diogenes of Sinope
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 198 bytes
Desc: Digital signature
URL: <http://lists.mplayerhq.hu/pipermail/ffmpeg-devel/attachments/20101006/1f72f38e/attachment.pgp>
More information about the ffmpeg-devel
mailing list