Merge "If we never triggered a range request but know the content length make sure to not read more data than there could be, otherwise we'd block indefinitely if the server doesn't close the connection."

This commit is contained in:
Andreas Huber
2010-02-16 14:41:14 -08:00
committed by Android (Google) Code Review
2 changed files with 17 additions and 2 deletions

View File

@@ -14,6 +14,10 @@
* limitations under the License.
*/
//#define LOG_NDEBUG 0
#define LOG_TAG "HTTPDataSource"
#include <utils/Log.h>
#include "include/stagefright_string.h"
#include "include/HTTPStream.h"
@@ -266,6 +270,8 @@ ssize_t HTTPDataSource::sendRangeRequest(size_t offset) {
}
ssize_t HTTPDataSource::readAt(off_t offset, void *data, size_t size) {
LOGV("readAt %ld, size %d", offset, size);
if (offset >= mBufferOffset
&& offset < (off_t)(mBufferOffset + mBufferLength)) {
size_t num_bytes_available = mBufferLength - (offset - mBufferOffset);
@@ -298,6 +304,15 @@ ssize_t HTTPDataSource::readAt(off_t offset, void *data, size_t size) {
mBufferOffset = offset;
if (mContentLengthValid
&& mBufferOffset + contentLength >= mContentLength) {
// If we never triggered a range request but know the content length,
// make sure to not read more data than there could be, otherwise
// we'd block indefinitely if the server doesn't close the connection.
contentLength = mContentLength - mBufferOffset;
}
if (contentLength <= 0) {
return contentLength;
}

View File

@@ -276,11 +276,11 @@ ssize_t HTTPStream::receive(void *data, size_t size) {
}
disconnect();
return total == 0 ? ERROR_IO : total;
return total == 0 ? (ssize_t)ERROR_IO : total;
} else if (n == 0) {
disconnect();
return total == 0 ? ERROR_CONNECTION_LOST : total;
return total == 0 ? (ssize_t)ERROR_CONNECTION_LOST : total;
}
total += (size_t)n;