no read loop tcp/http and http CRLF fix by (Leon van Stuivenberg <l dot vanstuivenberg at chello dot nl>)
Originally committed as revision 2885 to svn://svn.ffmpeg.org/ffmpeg/trunk
This commit is contained in:
parent
c3775e542f
commit
9eef2b77b2
@ -183,11 +183,11 @@ static int http_connect(URLContext *h, const char *path, const char *hoststr)
|
|||||||
post = h->flags & URL_WRONLY;
|
post = h->flags & URL_WRONLY;
|
||||||
|
|
||||||
snprintf(s->buffer, sizeof(s->buffer),
|
snprintf(s->buffer, sizeof(s->buffer),
|
||||||
"%s %s HTTP/1.0\n"
|
"%s %s HTTP/1.0\r\n"
|
||||||
"User-Agent: %s\n"
|
"User-Agent: %s\r\n"
|
||||||
"Accept: */*\n"
|
"Accept: */*\r\n"
|
||||||
"Host: %s\n"
|
"Host: %s\r\n"
|
||||||
"\n",
|
"\r\n",
|
||||||
post ? "POST" : "GET",
|
post ? "POST" : "GET",
|
||||||
path,
|
path,
|
||||||
LIBAVFORMAT_IDENT,
|
LIBAVFORMAT_IDENT,
|
||||||
@ -238,29 +238,19 @@ static int http_connect(URLContext *h, const char *path, const char *hoststr)
|
|||||||
static int http_read(URLContext *h, uint8_t *buf, int size)
|
static int http_read(URLContext *h, uint8_t *buf, int size)
|
||||||
{
|
{
|
||||||
HTTPContext *s = h->priv_data;
|
HTTPContext *s = h->priv_data;
|
||||||
int size1, len;
|
int len;
|
||||||
|
|
||||||
size1 = size;
|
/* read bytes from input buffer first */
|
||||||
while (size > 0) {
|
len = s->buf_end - s->buf_ptr;
|
||||||
/* read bytes from input buffer first */
|
if (len > 0) {
|
||||||
len = s->buf_end - s->buf_ptr;
|
if (len > size)
|
||||||
if (len > 0) {
|
len = size;
|
||||||
if (len > size)
|
memcpy(buf, s->buf_ptr, len);
|
||||||
len = size;
|
s->buf_ptr += len;
|
||||||
memcpy(buf, s->buf_ptr, len);
|
} else {
|
||||||
s->buf_ptr += len;
|
len = url_read(s->hd, buf, size);
|
||||||
} else {
|
|
||||||
len = url_read (s->hd, buf, size);
|
|
||||||
if (len < 0) {
|
|
||||||
return len;
|
|
||||||
} else if (len == 0) {
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
size -= len;
|
|
||||||
buf += len;
|
|
||||||
}
|
}
|
||||||
return size1 - size;
|
return len;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* used only when posting data */
|
/* used only when posting data */
|
||||||
|
@ -141,12 +141,11 @@ static int tcp_open(URLContext *h, const char *uri, int flags)
|
|||||||
static int tcp_read(URLContext *h, uint8_t *buf, int size)
|
static int tcp_read(URLContext *h, uint8_t *buf, int size)
|
||||||
{
|
{
|
||||||
TCPContext *s = h->priv_data;
|
TCPContext *s = h->priv_data;
|
||||||
int size1, len, fd_max;
|
int len, fd_max;
|
||||||
fd_set rfds;
|
fd_set rfds;
|
||||||
struct timeval tv;
|
struct timeval tv;
|
||||||
|
|
||||||
size1 = size;
|
for (;;) {
|
||||||
while (size > 0) {
|
|
||||||
if (url_interrupt_cb())
|
if (url_interrupt_cb())
|
||||||
return -EINTR;
|
return -EINTR;
|
||||||
fd_max = s->fd;
|
fd_max = s->fd;
|
||||||
@ -167,15 +166,9 @@ static int tcp_read(URLContext *h, uint8_t *buf, int size)
|
|||||||
#else
|
#else
|
||||||
return -errno;
|
return -errno;
|
||||||
#endif
|
#endif
|
||||||
else
|
} else break;
|
||||||
continue;
|
|
||||||
} else if (len == 0) {
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
size -= len;
|
|
||||||
buf += len;
|
|
||||||
}
|
}
|
||||||
return size1 - size;
|
return len;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int tcp_write(URLContext *h, uint8_t *buf, int size)
|
static int tcp_write(URLContext *h, uint8_t *buf, int size)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user