summaryrefslogtreecommitdiff
path: root/libavformat/http.c
diff options
context:
space:
mode:
authorJosh Allmann <joshua.allmann@gmail.com>2010-06-08 10:04:39 +0000
committerMartin Storsjö <martin@martin.st>2010-06-08 10:04:39 +0000
commit0f3254b83dcf7a13cabbf8a4ba271014b2ab147f (patch)
treeb1bcd0e87e295a3a62c5719d335ecdf09c49a565 /libavformat/http.c
parent8190f62f9b21b5013e2ce47073244b199482dd58 (diff)
Modify the behaviour of http_open to implicitly delay connection establishment
The connection is made on the first http_read, http_write or http_seek. Patch by Josh Allmann, joshua dot allmann at gmail Originally committed as revision 23525 to svn://svn.ffmpeg.org/ffmpeg/trunk
Diffstat (limited to 'libavformat/http.c')
-rw-r--r--libavformat/http.c26
1 files changed, 21 insertions, 5 deletions
diff --git a/libavformat/http.c b/libavformat/http.c
index 4e2152f5ef..855c67a155 100644
--- a/libavformat/http.c
+++ b/libavformat/http.c
@@ -45,6 +45,7 @@ typedef struct {
int64_t off, filesize;
char location[URL_SIZE];
HTTPAuthState auth_state;
+ int init;
} HTTPContext;
static int http_connect(URLContext *h, const char *path, const char *hoststr,
@@ -65,6 +66,7 @@ static int http_open_cnx(URLContext *h)
HTTPContext *s = h->priv_data;
URLContext *hd = NULL;
+ s->init = 1;
proxy_path = getenv("http_proxy");
use_proxy = (proxy_path != NULL) && !getenv("no_proxy") &&
av_strstart(proxy_path, "http://", NULL);
@@ -123,7 +125,6 @@ static int http_open_cnx(URLContext *h)
static int http_open(URLContext *h, const char *uri, int flags)
{
HTTPContext *s;
- int ret;
h->is_streamed = 1;
@@ -135,13 +136,11 @@ static int http_open(URLContext *h, const char *uri, int flags)
s->filesize = -1;
s->chunksize = -1;
s->off = 0;
+ s->init = 0;
memset(&s->auth_state, 0, sizeof(s->auth_state));
av_strlcpy(s->location, uri, URL_SIZE);
- ret = http_open_cnx(h);
- if (ret != 0)
- av_free (s);
- return ret;
+ return 0;
}
static int http_getc(HTTPContext *s)
{
@@ -322,6 +321,17 @@ static int http_read(URLContext *h, uint8_t *buf, int size)
HTTPContext *s = h->priv_data;
int len;
+ if (!s->init) {
+ int ret = http_open_cnx(h);
+ if (ret != 0)
+ return ret;
+ }
+
+ /* A size of zero can be used to force
+ * initializaton of the connection. */
+ if (!size)
+ return 0;
+
if (s->chunksize >= 0) {
if (!s->chunksize) {
char line[32];
@@ -369,6 +379,12 @@ static int http_write(URLContext *h, const uint8_t *buf, int size)
char crlf[] = "\r\n";
HTTPContext *s = h->priv_data;
+ if (!s->init) {
+ int ret = http_open_cnx(h);
+ if (ret != 0)
+ return ret;
+ }
+
if (s->chunksize == -1) {
/* headers are sent without any special encoding */
return url_write(s->hd, buf, size);