From 29908533cd18ec058f76096dbd435187e9293520 Mon Sep 17 00:00:00 2001 From: Aleric Inglewood Date: Tue, 31 Jul 2012 22:23:52 +0200 Subject: [PATCH] More work in progress --- indra/aistatemachine/aicurl.cpp | 7 +++-- .../aicurleasyrequeststatemachine.cpp | 4 +++ indra/aistatemachine/aicurlprivate.h | 2 +- indra/aistatemachine/aicurlthread.cpp | 4 +++ indra/llmessage/llhttpclient.cpp | 1 + indra/llmessage/llurlrequest.cpp | 31 ++++++++++--------- indra/llmessage/llurlrequest.h | 7 +++++ 7 files changed, 37 insertions(+), 19 deletions(-) diff --git a/indra/aistatemachine/aicurl.cpp b/indra/aistatemachine/aicurl.cpp index 090876f4e..1cbf1afaa 100644 --- a/indra/aistatemachine/aicurl.cpp +++ b/indra/aistatemachine/aicurl.cpp @@ -1231,12 +1231,12 @@ size_t CurlResponderBuffer::curlWriteCallback(char* data, size_t size, size_t nm // to make sure that callbacks and destruction aren't done simultaneously. AICurlEasyRequest_wat buffered_easy_request_w(*lockobj); + S32 bytes = size * nmemb; // The amount to write. AICurlResponderBuffer_wat buffer_w(*lockobj); // CurlResponderBuffer::setBodyLimit is never called, so buffer_w->mBodyLimit is infinite. //S32 bytes = llmin(size * nmemb, buffer_w->mBodyLimit); buffer_w->mBodyLimit -= bytes; - S32 bytes = size * nmemb; buffer_w->getOutput()->append(sChannels.in(), (U8 const*)data, bytes); - mResponseTransferedBytes += bytes; + buffer_w->mResponseTransferedBytes += bytes; // Accumulate data received from the server. return bytes; } @@ -1252,7 +1252,8 @@ size_t CurlResponderBuffer::curlReadCallback(char* data, size_t size, size_t nme S32 bytes = size * nmemb; // The maximum amount to read. AICurlResponderBuffer_wat buffer_w(*lockobj); buffer_w->mLastRead = buffer_w->getInput()->readAfter(sChannels.out(), buffer_w->mLastRead, (U8*)data, bytes); - return bytes; // Return the amount actually read. + buffer_w->mRequestTransferedBytes += bytes; // Accumulate data sent to the server. + return bytes; // Return the amount actually read (might be lowered by readAfter()). } //static diff --git a/indra/aistatemachine/aicurleasyrequeststatemachine.cpp b/indra/aistatemachine/aicurleasyrequeststatemachine.cpp index 221bfdfb2..d6ab002db 100644 --- a/indra/aistatemachine/aicurleasyrequeststatemachine.cpp +++ b/indra/aistatemachine/aicurleasyrequeststatemachine.cpp @@ -239,6 +239,10 @@ void AICurlEasyRequestStateMachine::finish_impl(void) AICurlEasyRequestStateMachine::AICurlEasyRequestStateMachine(bool buffered) : mBuffered(buffered), mCurlEasyRequest(buffered) { Dout(dc::statemachine, "Calling AICurlEasyRequestStateMachine(" << (buffered ? "true" : "false") << ") [" << (void*)this << "] [" << (void*)mCurlEasyRequest.get() << "]"); + if (!mBuffered) + { + llwarns << "Using unbuffered AICurlEasyRequestStateMachine" << llendl; + } } //static diff --git a/indra/aistatemachine/aicurlprivate.h b/indra/aistatemachine/aicurlprivate.h index acd3a808c..a99224f96 100644 --- a/indra/aistatemachine/aicurlprivate.h +++ b/indra/aistatemachine/aicurlprivate.h @@ -316,7 +316,7 @@ class CurlResponderBuffer : protected AICurlEasyHandleEvents { LLIOPipe::buffer_ptr_t mOutput; AICurlInterface::ResponderPtr mResponder; //U32 mBodyLimit; // From the old LLURLRequestDetail::mBodyLimit, but never used. - S32 mByteAccumulator; + S32 mRequestTransferedBytes; S32 mResponseTransferedBytes; public: diff --git a/indra/aistatemachine/aicurlthread.cpp b/indra/aistatemachine/aicurlthread.cpp index c75912047..65ef1317b 100644 --- a/indra/aistatemachine/aicurlthread.cpp +++ b/indra/aistatemachine/aicurlthread.cpp @@ -39,7 +39,11 @@ #endif #include +// On linux, add -DDEBUG_WINDOWS_CODE_ON_LINUX to test the windows code used in this file. +#if !defined(DEBUG_WINDOWS_CODE_ON_LINUX) || !defined(LL_LINUX) || defined(LL_RELEASE) +#undef DEBUG_WINDOWS_CODE_ON_LINUX #define DEBUG_WINDOWS_CODE_ON_LINUX 0 +#endif #if DEBUG_WINDOWS_CODE_ON_LINUX diff --git a/indra/llmessage/llhttpclient.cpp b/indra/llmessage/llhttpclient.cpp index 9aef7d837..e954dcd1b 100644 --- a/indra/llmessage/llhttpclient.cpp +++ b/indra/llmessage/llhttpclient.cpp @@ -298,6 +298,7 @@ static void request( } //AIFIXME: req->setCallback(new LLHTTPClientURLAdaptor(responder)); + llassert_always(false); if (method == LLURLRequest::HTTP_POST && gMessageSystem) { diff --git a/indra/llmessage/llurlrequest.cpp b/indra/llmessage/llurlrequest.cpp index c54b2a837..e66dc3c1b 100644 --- a/indra/llmessage/llurlrequest.cpp +++ b/indra/llmessage/llurlrequest.cpp @@ -147,19 +147,12 @@ std::string LLURLRequest::actionAsVerb(LLURLRequest::ERequestAction action) } // This might throw AICurlNoEasyHandle. -LLURLRequest::LLURLRequest(LLURLRequest::ERequestAction action, std::string const& url) : AICurlEasyRequestStateMachine(false), mAction(action), mURL(url) +LLURLRequest::LLURLRequest(LLURLRequest::ERequestAction action, std::string const& url) : AICurlEasyRequestStateMachine(true), mAction(action), mURL(url) { LLMemType m1(LLMemType::MTYPE_IO_URL_REQUEST); - { - AICurlEasyRequest_wat curlEasyRequest_w(*mCurlEasyRequest); - //AIFIXME: we can't really use the other callbacks: they have to be extended... curlEasyRequest_w->setWriteCallback(&downCallback, (void*)this); - //AIFIXME: curlEasyRequest_w->setReadCallback(&upCallback, (void*)this); - } - - //AIFIXME: stuff they have to be extended with... mRequestTransferedBytes = 0; - //AIFIXME: stuff they have to be extended with... mResponseTransferedBytes = 0; //AIFIXME: start statemachine mState = STATE_INITIALIZED; + llassert_always(false); } #if 0 @@ -468,6 +461,13 @@ LLIOPipe::EStatus LLURLRequest::process_impl( } #endif // AI_UNUSED +S32 LLURLRequest::bytes_to_send(void) const +{ + //AIFIXME: how to get the number of bytes to send? + llassert_always(false); + return 0; +} + static LLFastTimer::DeclareTimer FTM_URL_REQUEST_CONFIGURE("URL Configure"); bool LLURLRequest::configure() { @@ -475,9 +475,6 @@ bool LLURLRequest::configure() LLMemType m1(LLMemType::MTYPE_IO_URL_REQUEST); bool rv = false; - S32 bytes = mDetail->mResponseBuffer->countAfter( - mDetail->mChannels.in(), - NULL); { AICurlEasyRequest_wat curlEasyRequest_w(*mCurlEasyRequest); switch(mAction) @@ -498,16 +495,19 @@ bool LLURLRequest::configure() break; case HTTP_PUT: + { // Disable the expect http 1.1 extension. POST and PUT default // to turning this on, and I am not too sure what it means. addHeader("Expect:"); + S32 bytes = bytes_to_send(); curlEasyRequest_w->setopt(CURLOPT_UPLOAD, 1); curlEasyRequest_w->setopt(CURLOPT_INFILESIZE, bytes); rv = true; break; - + } case HTTP_POST: + { // Disable the expect http 1.1 extension. POST and PUT default // to turning this on, and I am not too sure what it means. addHeader("Expect:"); @@ -517,13 +517,14 @@ bool LLURLRequest::configure() addHeader("Content-Type:"); // Set the handle for an http post + S32 bytes = bytes_to_send(); curlEasyRequest_w->setPost(NULL, bytes); // Set Accept-Encoding to allow response compression curlEasyRequest_w->setoptString(CURLOPT_ENCODING, ""); rv = true; break; - + } case HTTP_DELETE: // Set the handle for an http post curlEasyRequest_w->setoptString(CURLOPT_CUSTOMREQUEST, "DELETE"); @@ -543,7 +544,7 @@ bool LLURLRequest::configure() } if(rv) { - curlEasyRequest_w->finalizeRequest(mDetail->mURL); + curlEasyRequest_w->finalizeRequest(mURL); } } return rv; diff --git a/indra/llmessage/llurlrequest.h b/indra/llmessage/llurlrequest.h index 9a20d8cc6..65b714556 100644 --- a/indra/llmessage/llurlrequest.h +++ b/indra/llmessage/llurlrequest.h @@ -97,6 +97,13 @@ class LLURLRequest : public AICurlEasyRequestStateMachine { */ bool configure(void); + /** + * @ brief Return the number of bytes to POST or PUT to the server. + * + * @return Returns the number of bytes we're about to upload. + */ + S32 bytes_to_send(void) const; + private: ERequestAction mAction; std::string mURL;