[FFmpeg-devel] [PATCH 4/4] HTTP: handle non-blocking

Nicolas George nicolas.george
Fri Feb 18 18:59:23 CET 2011


Signed-off-by: Nicolas George <nicolas.george at normalesup.org>
---
 libavformat/http.c |   18 +++++++++++-------
 1 files changed, 11 insertions(+), 7 deletions(-)

diff --git a/libavformat/http.c b/libavformat/http.c
index 6337b85..4e3bc38 100644
--- a/libavformat/http.c
+++ b/libavformat/http.c
@@ -146,6 +146,8 @@ static int http_open_cnx(URLContext *h)
         location_changed = 0;
         goto redo;
     }
+    if (h->flags & URL_FLAG_NONBLOCK)
+        url_set_nonblock(h->slave, 1);
     return 0;
  fail:
     if (hd)
@@ -172,9 +174,9 @@ static int http_getc(URLContext *h)
     if (s->buf_ptr >= s->buf_end) {
         len = url_read(h->slave, s->buffer, BUFFER_SIZE);
         if (len < 0) {
-            return AVERROR(EIO);
+            return len;
         } else if (len == 0) {
-            return -1;
+            return AVERROR_EOF;
         } else {
             s->buf_ptr = s->buffer;
             s->buf_end = s->buffer + len;
@@ -192,7 +194,7 @@ static int http_get_line(URLContext *h, char *line, int line_size)
     for(;;) {
         ch = http_getc(h);
         if (ch < 0)
-            return AVERROR(EIO);
+            return ch;
         if (ch == '\n') {
             /* process line */
             if (q > line && q[-1] == '\r')
@@ -353,8 +355,9 @@ static int http_connect(URLContext *h, const char *path, const char *hoststr,
 
     /* wait for header */
     for(;;) {
-        if (http_get_line(h, line, sizeof(line)) < 0)
-            return AVERROR(EIO);
+        err = http_get_line(h, line, sizeof(line));
+        if (err < 0)
+            return err;
 
         av_dlog(NULL, "header='%s'\n", line);
 
@@ -381,8 +384,9 @@ static int http_read(URLContext *h, uint8_t *buf, int size)
 
             for(;;) {
                 do {
-                    if (http_get_line(h, line, sizeof(line)) < 0)
-                        return AVERROR(EIO);
+                    int err = http_get_line(h, line, sizeof(line));
+                    if (err < 0)
+                        return err;
                 } while (!*line);    /* skip CR LF from last chunk */
 
                 s->chunksize = strtoll(line, NULL, 16);
-- 
1.7.2.3




More information about the ffmpeg-devel mailing list