aboutsummaryrefslogtreecommitdiffstats
path: root/src/inputStream_http.c
diff options
context:
space:
mode:
authorWarren Dukes <warren.dukes@gmail.com>2004-05-18 09:54:45 +0000
committerWarren Dukes <warren.dukes@gmail.com>2004-05-18 09:54:45 +0000
commit6c24180516f823985f564ba013607b47f70afa81 (patch)
tree8b3ac9478f5ab1c9aee4b41cefeae603d6a61d90 /src/inputStream_http.c
parentd4c7d6df6db478cbbfb0cba11a8a42aed9070d62 (diff)
downloadmpd-6c24180516f823985f564ba013607b47f70afa81.tar.gz
mpd-6c24180516f823985f564ba013607b47f70afa81.tar.xz
mpd-6c24180516f823985f564ba013607b47f70afa81.zip
inputStream updates from httpTest
git-svn-id: https://svn.musicpd.org/mpd/trunk@1059 09075e82-0dd4-0310-85a5-a0d7c8717e4f
Diffstat (limited to '')
-rw-r--r--src/inputStream_http.c94
1 files changed, 56 insertions, 38 deletions
diff --git a/src/inputStream_http.c b/src/inputStream_http.c
index 330d5905a..c2c1b0904 100644
--- a/src/inputStream_http.c
+++ b/src/inputStream_http.c
@@ -423,6 +423,7 @@ int inputStream_httpOpen(InputStream * inStream, char * url) {
inStream->closeFunc = inputStream_httpClose;
inStream->readFunc = inputStream_httpRead;
inStream->atEOFFunc = inputStream_httpAtEOF;
+ inStream->bufferFunc = inputStream_httpBuffer;
inStream->offset = 0;
inStream->size = 0;
@@ -443,20 +444,71 @@ size_t inputStream_httpRead(InputStream * inStream, void * ptr, size_t size,
InputStreamHTTPData * data = (InputStreamHTTPData *)inStream->data;
int readed = 0;
int inlen = size*nmemb;
+
+ inputStream_httpBuffer(inStream);
+
+ switch(data->connState) {
+ case HTTP_CONN_STATE_OPEN:
+ case HTTP_CONN_STATE_CLOSED:
+ break;
+ default:
+ return 0;
+ }
+
+ readed = inlen > data->buflen ? data->buflen : inlen;
+
+ memcpy(ptr, data->buffer, readed);
+ data->buflen -= readed;
+ memmove(data->buffer, data->buffer+readed, data->buflen);
+
+ inStream->offset+= readed;
+
+ return readed;
+}
+
+int inputStream_httpClose(InputStream * inStream) {
+ InputStreamHTTPData * data = (InputStreamHTTPData *)inStream->data;
+
+ switch(data->connState) {
+ case HTTP_CONN_STATE_CLOSED:
+ break;
+ default:
+ close(data->sock);
+ }
+
+ if(inStream->mime) free(inStream->mime);
+ freeInputStreamHTTPData(data);
+
+ return 0;
+}
+
+int inputStream_httpAtEOF(InputStream * inStream) {
+ InputStreamHTTPData * data = (InputStreamHTTPData *)inStream->data;
+ switch(data->connState) {
+ case HTTP_CONN_STATE_CLOSED:
+ if(data->buflen == 0) return 1;
+ default:
+ return 0;
+ }
+}
+
+int inputStream_httpBuffer(InputStream * inStream) {
+ InputStreamHTTPData * data = (InputStreamHTTPData *)inStream->data;
+ int readed = 0;
fd_set readSet;
struct timeval tv;
int ret;
if(data->connState == HTTP_CONN_STATE_REOPEN) {
- if(initHTTPConnection(inStream) < 0) return 0;
+ if(initHTTPConnection(inStream) < 0) return -1;
}
if(data->connState == HTTP_CONN_STATE_INIT) {
- if(finishHTTPInit(inStream) < 0) return 0;
+ if(finishHTTPInit(inStream) < 0) return -1;
}
if(data->connState == HTTP_CONN_STATE_HELLO) {
- if(getHTTPHello(inStream) < 0) return 0;
+ if(getHTTPHello(inStream) < 0) return -1;
}
switch(data->connState) {
@@ -464,7 +516,7 @@ size_t inputStream_httpRead(InputStream * inStream, void * ptr, size_t size,
case HTTP_CONN_STATE_CLOSED:
break;
default:
- return 0;
+ return -1;
}
if(data->connState == HTTP_CONN_STATE_OPEN &&
@@ -502,40 +554,6 @@ size_t inputStream_httpRead(InputStream * inStream, void * ptr, size_t size,
}
}
- readed = inlen > data->buflen ? data->buflen : inlen;
-
- memcpy(ptr, data->buffer, readed);
- data->buflen -= readed;
- memmove(data->buffer, data->buffer+readed, data->buflen);
-
- inStream->offset+= readed;
-
- return readed;
-}
-
-int inputStream_httpClose(InputStream * inStream) {
- InputStreamHTTPData * data = (InputStreamHTTPData *)inStream->data;
-
- switch(data->connState) {
- case HTTP_CONN_STATE_CLOSED:
- break;
- default:
- close(data->sock);
- }
-
- if(inStream->mime) free(inStream->mime);
- freeInputStreamHTTPData(data);
-
return 0;
}
-
-int inputStream_httpAtEOF(InputStream * inStream) {
- InputStreamHTTPData * data = (InputStreamHTTPData *)inStream->data;
- switch(data->connState) {
- case HTTP_CONN_STATE_CLOSED:
- if(data->buflen == 0) return 1;
- default:
- return 0;
- }
-}
/* vim:set shiftwidth=8 tabstop=8 expandtab: */