summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMonty Brandenberg <monty@lindenlab.com>2012-06-11 17:47:04 -0400
committerMonty Brandenberg <monty@lindenlab.com>2012-06-11 17:47:04 -0400
commit267ab5b417eaef64a170d69ad83334df9d566ed9 (patch)
tree39b082be67c26ba6990c71f9265d222279030260
parent89187229dd630845177ecd7a16e2b9cb01dc47ce (diff)
Convert BufferArray interfaces to void * (not char *). HttpRequest::update() honor time limit.
Generally, opaque data operations are expected to be over 'void *' and have now converted interfaces to do that. Update() method honors millisecond limit to dwell time. Might want to homologate the millis/uSecs mix later....
-rw-r--r--indra/llcorehttp/bufferarray.cpp37
-rw-r--r--indra/llcorehttp/bufferarray.h8
-rw-r--r--indra/llcorehttp/httprequest.cpp13
-rw-r--r--indra/llcorehttp/httprequest.h2
-rw-r--r--indra/llcorehttp/tests/test_bufferarray.hpp6
5 files changed, 34 insertions, 32 deletions
diff --git a/indra/llcorehttp/bufferarray.cpp b/indra/llcorehttp/bufferarray.cpp
index 36a8006bce..6d5309a043 100644
--- a/indra/llcorehttp/bufferarray.cpp
+++ b/indra/llcorehttp/bufferarray.cpp
@@ -108,10 +108,11 @@ BufferArray::~BufferArray()
}
-size_t BufferArray::append(const char * src, size_t len)
+size_t BufferArray::append(const void * src, size_t len)
{
const size_t ret(len);
-
+ const char * c_src(static_cast<const char *>(src));
+
// First, try to copy into the last block
if (len && ! mBlocks.empty())
{
@@ -121,11 +122,11 @@ size_t BufferArray::append(const char * src, size_t len)
// Some will fit...
const size_t copy_len((std::min)(len, (last.mAlloced - last.mUsed)));
- memcpy(&last.mData[last.mUsed], src, copy_len);
+ memcpy(&last.mData[last.mUsed], c_src, copy_len);
last.mUsed += copy_len;
llassert_always(last.mUsed <= last.mAlloced);
mLen += copy_len;
- src += copy_len;
+ c_src += copy_len;
len -= copy_len;
}
}
@@ -140,19 +141,19 @@ size_t BufferArray::append(const char * src, size_t len)
mBlocks.reserve(mBlocks.size() + 5);
}
Block * block = Block::alloc(BLOCK_ALLOC_SIZE);
- memcpy(block->mData, src, copy_len);
+ memcpy(block->mData, c_src, copy_len);
block->mUsed = copy_len;
llassert_always(block->mUsed <= block->mAlloced);
mBlocks.push_back(block);
mLen += copy_len;
- src += copy_len;
+ c_src += copy_len;
len -= copy_len;
}
return ret;
}
-char * BufferArray::appendBufferAlloc(size_t len)
+void * BufferArray::appendBufferAlloc(size_t len)
{
// If someone asks for zero-length, we give them a valid pointer.
if (mBlocks.size() >= mBlocks.capacity())
@@ -167,8 +168,10 @@ char * BufferArray::appendBufferAlloc(size_t len)
}
-size_t BufferArray::read(size_t pos, char * dst, size_t len)
+size_t BufferArray::read(size_t pos, void * dst, size_t len)
{
+ char * c_dst(static_cast<char *>(dst));
+
if (pos >= mLen)
return 0;
size_t len_limit(mLen - pos);
@@ -188,10 +191,10 @@ size_t BufferArray::read(size_t pos, char * dst, size_t len)
size_t block_limit(block.mUsed - offset);
size_t block_len(std::min(block_limit, len));
- memcpy(dst, &block.mData[offset], block_len);
+ memcpy(c_dst, &block.mData[offset], block_len);
result += block_len;
len -= block_len;
- dst += block_len;
+ c_dst += block_len;
offset = 0;
++block_start;
}
@@ -201,8 +204,10 @@ size_t BufferArray::read(size_t pos, char * dst, size_t len)
}
-size_t BufferArray::write(size_t pos, const char * src, size_t len)
+size_t BufferArray::write(size_t pos, const void * src, size_t len)
{
+ const char * c_src(static_cast<const char *>(src));
+
if (pos > mLen || 0 == len)
return 0;
@@ -220,9 +225,9 @@ size_t BufferArray::write(size_t pos, const char * src, size_t len)
size_t block_limit(block.mUsed - offset);
size_t block_len(std::min(block_limit, len));
- memcpy(&block.mData[offset], src, block_len);
+ memcpy(&block.mData[offset], c_src, block_len);
result += block_len;
- src += block_len;
+ c_src += block_len;
len -= block_len;
offset = 0;
++block_start;
@@ -240,12 +245,12 @@ size_t BufferArray::write(size_t pos, const char * src, size_t len)
// Some will fit...
const size_t copy_len((std::min)(len, (last.mAlloced - last.mUsed)));
- memcpy(&last.mData[last.mUsed], src, copy_len);
+ memcpy(&last.mData[last.mUsed], c_src, copy_len);
last.mUsed += copy_len;
result += copy_len;
llassert_always(last.mUsed <= last.mAlloced);
mLen += copy_len;
- src += copy_len;
+ c_src += copy_len;
len -= copy_len;
}
}
@@ -254,7 +259,7 @@ size_t BufferArray::write(size_t pos, const char * src, size_t len)
{
// Some or all of the remaining write data will
// be an append.
- result += append(src, len);
+ result += append(c_src, len);
}
return result;
diff --git a/indra/llcorehttp/bufferarray.h b/indra/llcorehttp/bufferarray.h
index 9ccd85d4f8..72c3e1c669 100644
--- a/indra/llcorehttp/bufferarray.h
+++ b/indra/llcorehttp/bufferarray.h
@@ -81,7 +81,7 @@ public:
/// position is one beyond the final byte of the buffer.
///
/// @return Count of bytes copied to BufferArray
- size_t append(const char * src, size_t len);
+ size_t append(const void * src, size_t len);
/// Similar to @see append(), this call guarantees a
/// contiguous block of memory of requested size placed
@@ -91,7 +91,7 @@ public:
///
/// @return Pointer to contiguous region at end
/// of BufferArray of 'len' size.
- char * appendBufferAlloc(size_t len);
+ void * appendBufferAlloc(size_t len);
/// Current count of bytes in BufferArray instance.
size_t size() const
@@ -102,13 +102,13 @@ public:
/// Copies data from the given position in the instance
/// to the caller's buffer. Will return a short count of
/// bytes copied if the 'len' extends beyond the data.
- size_t read(size_t pos, char * dst, size_t len);
+ size_t read(size_t pos, void * dst, size_t len);
/// Copies data from the caller's buffer to the instance
/// at the current position. May overwrite existing data,
/// append data when current position is equal to the
/// size of the instance or do a mix of both.
- size_t write(size_t pos, const char * src, size_t len);
+ size_t write(size_t pos, const void * src, size_t len);
protected:
int findBlock(size_t pos, size_t * ret_offset);
diff --git a/indra/llcorehttp/httprequest.cpp b/indra/llcorehttp/httprequest.cpp
index baa0fe1a84..2f36168f8b 100644
--- a/indra/llcorehttp/httprequest.cpp
+++ b/indra/llcorehttp/httprequest.cpp
@@ -35,6 +35,8 @@
#include "_httpopsetpriority.h"
#include "_httpopcancel.h"
+#include "lltimer.h"
+
namespace
{
@@ -279,14 +281,9 @@ HttpHandle HttpRequest::requestSetPriority(HttpHandle request, priority_t priori
HttpStatus HttpRequest::update(long millis)
{
- HttpStatus status;
-
- // *FIXME: need timer stuff
- // long now(getNow());
- // long limit(now + millis);
-
+ const HttpTime limit(totalTime() + (1000 * HttpTime(millis)));
HttpOperation * op(NULL);
- while ((op = mReplyQueue->fetchOp()))
+ while (limit >= totalTime() && (op = mReplyQueue->fetchOp()))
{
// Process operation
op->visitNotifier(this);
@@ -295,7 +292,7 @@ HttpStatus HttpRequest::update(long millis)
op->release();
}
- return status;
+ return HttpStatus();
}
diff --git a/indra/llcorehttp/httprequest.h b/indra/llcorehttp/httprequest.h
index 3592d5c6a3..01dbfba6dd 100644
--- a/indra/llcorehttp/httprequest.h
+++ b/indra/llcorehttp/httprequest.h
@@ -259,7 +259,7 @@ public:
/// @param millis Maximum number of wallclock milliseconds to
/// spend in the call. As hinted at above, this
/// is partly a function of application code so it's
- /// a soft limit. (And not currently implemented.)
+ /// a soft limit.
///
/// @return Standard status code.
HttpStatus update(long millis);
diff --git a/indra/llcorehttp/tests/test_bufferarray.hpp b/indra/llcorehttp/tests/test_bufferarray.hpp
index 2ad9391d1c..3f947db967 100644
--- a/indra/llcorehttp/tests/test_bufferarray.hpp
+++ b/indra/llcorehttp/tests/test_bufferarray.hpp
@@ -348,7 +348,7 @@ void BufferArrayTestObjectType::test<7>()
ensure("Append length correct", str2_len == len);
// append some more
- char * out_buf(ba->appendBufferAlloc(str1_len));
+ void * out_buf(ba->appendBufferAlloc(str1_len));
memcpy(out_buf, str1, str1_len);
// And some final writes
@@ -399,11 +399,11 @@ void BufferArrayTestObjectType::test<8>()
len = ba->write(str1_len, str1, str1_len);
// zero-length allocate (we allow this with a valid pointer returned)
- char * out_buf(ba->appendBufferAlloc(0));
+ void * out_buf(ba->appendBufferAlloc(0));
ensure("Buffer from zero-length appendBufferAlloc non-NULL", NULL != out_buf);
// Do it again
- char * out_buf2(ba->appendBufferAlloc(0));
+ void * out_buf2(ba->appendBufferAlloc(0));
ensure("Buffer from zero-length appendBufferAlloc non-NULL.2", NULL != out_buf2);
ensure("Two zero-length appendBufferAlloc buffers distinct", out_buf != out_buf2);