aboutsummaryrefslogtreecommitdiffstats
path: root/src
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
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.c4
-rw-r--r--src/inputStream.h3
-rw-r--r--src/inputStream_file.c5
-rw-r--r--src/inputStream_file.h2
-rw-r--r--src/inputStream_http.c94
-rw-r--r--src/inputStream_http.h2
6 files changed, 72 insertions, 38 deletions
diff --git a/src/inputStream.c b/src/inputStream.c
index 578749e24..6ff2d1bd5 100644
--- a/src/inputStream.c
+++ b/src/inputStream.c
@@ -49,4 +49,8 @@ int closeInputStream(InputStream * inStream) {
int inputStreamAtEOF(InputStream * inStream) {
return inStream->atEOFFunc(inStream);
}
+
+int bufferInputStream(InputStream * inStream) {
+ return inStream->bufferFunc(inStream);
+}
/* vim:set shiftwidth=8 tabstop=8 expandtab: */
diff --git a/src/inputStream.h b/src/inputStream.h
index bcf57c85b..963e3d2c9 100644
--- a/src/inputStream.h
+++ b/src/inputStream.h
@@ -29,6 +29,7 @@ typedef size_t (* InputStreamReadFunc) (InputStream * inStream, void * ptr, size
size_t nmemb);
typedef int (* InputStreamCloseFunc) (InputStream * inStream);
typedef int (* InputStreamAtEOFFunc) (InputStream * inStream);
+typedef int (* InputStreamBufferFunc) (InputStream * inStream);
struct _InputStream {
int error;
@@ -42,6 +43,7 @@ struct _InputStream {
InputStreamReadFunc readFunc;
InputStreamCloseFunc closeFunc;
InputStreamAtEOFFunc atEOFFunc;
+ InputStreamBufferFunc bufferFunc;
void * data;
};
@@ -51,6 +53,7 @@ int openInputStream(InputStream * inStream, char * url);
int seekInputStream(InputStream * inStream, long offset, int whence);
int closeInputStream(InputStream * inStream);
int inputStreamAtEOF(InputStream * inStream);
+int bufferInputStream(InputStream * inStream);
size_t readFromInputStream(InputStream * inStream, void * ptr, size_t size,
size_t nmemb);
diff --git a/src/inputStream_file.c b/src/inputStream_file.c
index 9c03fe826..b71beea95 100644
--- a/src/inputStream_file.c
+++ b/src/inputStream_file.c
@@ -45,6 +45,7 @@ int inputStream_fileOpen(InputStream * inStream, char * filename) {
inStream->closeFunc = inputStream_fileClose;
inStream->readFunc = inputStream_fileRead;
inStream->atEOFFunc = inputStream_fileAtEOF;
+ inStream->bufferFunc = inputStream_fileBuffer;
return 0;
}
@@ -85,4 +86,8 @@ int inputStream_fileClose(InputStream * inStream) {
int inputStream_fileAtEOF(InputStream * inStream) {
return feof((FILE *)inStream->data);
}
+
+int inputStream_fileBuffer(InputStream * inStream) {
+ return 0;
+}
/* vim:set shiftwidth=4 tabstop=8 expandtab: */
diff --git a/src/inputStream_file.h b/src/inputStream_file.h
index 694606cc9..b4b53f3c0 100644
--- a/src/inputStream_file.h
+++ b/src/inputStream_file.h
@@ -32,5 +32,7 @@ int inputStream_fileClose(InputStream * inStream);
int inputStream_fileAtEOF(InputStream * inStream);
+int inputStream_fileBuffer(InputStream * inStream);
+
#endif
/* vim:set shiftwidth=8 tabstop=8 expandtab: */
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: */
diff --git a/src/inputStream_http.h b/src/inputStream_http.h
index 4fea5f79e..021ae2c76 100644
--- a/src/inputStream_http.h
+++ b/src/inputStream_http.h
@@ -32,5 +32,7 @@ int inputStream_httpClose(InputStream * inStream);
int inputStream_httpAtEOF(InputStream * inStream);
+int inputStream_httpBuffer(InputStream * inStream);
+
#endif
/* vim:set shiftwidth=8 tabstop=8 expandtab: */