summaryrefslogtreecommitdiff
path: root/ext/curl/curlstreams.c
diff options
context:
space:
mode:
authorWez Furlong <wez@php.net>2002-09-23 01:47:04 +0000
committerWez Furlong <wez@php.net>2002-09-23 01:47:04 +0000
commit4d8a07d52908505e1516e6cef455debb07f1c2e2 (patch)
tree19a7390f43764582533dba4f4733479fc48cc9b6 /ext/curl/curlstreams.c
parent625e7b202bee50d4d2689e23e326aef1f94f08b4 (diff)
downloadphp-git-4d8a07d52908505e1516e6cef455debb07f1c2e2.tar.gz
Implement read buffering in streams.
Eliminate similar code from network.c. Implement fgets equivalent at the streams level, which can detect the mac, dos and unix line endings and handle them appropriately. The default behaviour is unix (and dos) line endings. An ini option to control this behaviour will follow. # Don't forget to make clean! # I've done some testing but would appreciate feedback from # people with scripts/extensions that seek around a lot.
Diffstat (limited to 'ext/curl/curlstreams.c')
-rw-r--r--ext/curl/curlstreams.c39
1 files changed, 21 insertions, 18 deletions
diff --git a/ext/curl/curlstreams.c b/ext/curl/curlstreams.c
index dcffdfaf5f..eaee95409d 100644
--- a/ext/curl/curlstreams.c
+++ b/ext/curl/curlstreams.c
@@ -145,7 +145,8 @@ static size_t php_curl_stream_read(php_stream *stream, char *buf, size_t count T
/* check for EOF */
/* if we have buffered data, then we are not at EOF */
- if (curlstream->readbuffer.writepos > 0 && curlstream->readbuffer.readpos < curlstream->readbuffer.writepos)
+ if (curlstream->readbuffer.writepos > 0
+ && curlstream->readbuffer.readpos < curlstream->readbuffer.writepos)
return 0;
@@ -172,7 +173,8 @@ static size_t php_curl_stream_read(php_stream *stream, char *buf, size_t count T
tv.tv_sec = 15; /* TODO: allow this to be configured from the script */
/* wait for data */
- switch (select(curlstream->maxfd+1, &curlstream->readfds, &curlstream->writefds, &curlstream->excfds, &tv)) {
+ switch (select(curlstream->maxfd+1, &curlstream->readfds,
+ &curlstream->writefds, &curlstream->excfds, &tv)) {
case -1:
/* error */
return 0;
@@ -233,21 +235,6 @@ static int php_curl_stream_stat(php_stream *stream, php_stream_statbuf *ssb TSRM
return -1;
}
-static char *php_curl_stream_gets(php_stream *stream, char *buf, size_t size TSRMLS_DC)
-{
- php_curl_stream *curlstream = (php_curl_stream*)stream->abstract;
- char *ret;
-
- php_stream_seek(curlstream->readbuffer.buf, curlstream->readbuffer.readpos, SEEK_SET);
- ret = php_stream_gets(curlstream->readbuffer.buf, buf, size);
- curlstream->readbuffer.readpos = php_stream_tell(curlstream->readbuffer.buf);
-
- if (ret > 0)
- return buf;
-
- return NULL;
-}
-
static int php_curl_stream_cast(php_stream *stream, int castas, void **ret TSRMLS_DC)
{
php_curl_stream *curlstream = (php_curl_stream*)stream->abstract;
@@ -262,7 +249,6 @@ PHPAPI php_stream_ops php_curl_stream_ops = {
php_curl_stream_flush,
"cURL",
NULL, /* seek */
- php_curl_stream_gets, /* gets */
php_curl_stream_cast, /* cast */
php_curl_stream_stat /* stat */
};
@@ -357,7 +343,24 @@ PHPAPI php_stream *php_curl_stream_opener(php_stream_wrapper *wrapper, char *fil
curl_easy_perform(curlstream->curl);
}
+ else
#endif
+ {
+ /* fire up the connection; we need to detect a connection error here,
+ * otherwise the curlstream we return ends up doing nothing useful. */
+ CURLMcode m;
+
+ while (CURLM_CALL_MULTI_PERFORM ==
+ (m = curl_multi_perform(curlstream->multi, &curlstream->pending))
+ ) {
+ ; /* spin */
+ }
+
+ if (m != CURLM_OK) {
+ php_error_docref(NULL TSRMLS_CC, E_WARNING, "There was an error mcode=%d", m);
+ }
+
+ }
return stream;
}