aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/linden/indra
diff options
context:
space:
mode:
authorJacek Antonelli2010-02-08 19:01:20 -0600
committerJacek Antonelli2010-02-08 19:01:20 -0600
commite7b590f6c90cefac0861a906523c398613ad1321 (patch)
tree73e7f88f726ca3ae3bbbeeed38874ef8f8538aa0 /linden/indra
parentPorted some thread changes from Snowglobe. (diff)
downloadmeta-impy-e7b590f6c90cefac0861a906523c398613ad1321.zip
meta-impy-e7b590f6c90cefac0861a906523c398613ad1321.tar.gz
meta-impy-e7b590f6c90cefac0861a906523c398613ad1321.tar.bz2
meta-impy-e7b590f6c90cefac0861a906523c398613ad1321.tar.xz
Ported some cURL and HTTP-related changes from Snowglobe.
Diffstat (limited to '')
-rw-r--r--linden/indra/llmessage/llcurl.cpp34
-rw-r--r--linden/indra/llmessage/llcurl.h7
-rw-r--r--linden/indra/llmessage/llhttpclient.cpp14
3 files changed, 39 insertions, 16 deletions
diff --git a/linden/indra/llmessage/llcurl.cpp b/linden/indra/llmessage/llcurl.cpp
index 811d4af..12321fe 100644
--- a/linden/indra/llmessage/llcurl.cpp
+++ b/linden/indra/llmessage/llcurl.cpp
@@ -220,7 +220,7 @@ public:
220 U32 report(CURLcode); 220 U32 report(CURLcode);
221 void getTransferInfo(LLCurl::TransferInfo* info); 221 void getTransferInfo(LLCurl::TransferInfo* info);
222 222
223 void prepRequest(const std::string& url, ResponderPtr, bool post = false); 223 void prepRequest(const std::string& url, const std::vector<std::string>& headers, ResponderPtr, bool post = false);
224 224
225 const char* getErrorBuffer(); 225 const char* getErrorBuffer();
226 226
@@ -432,7 +432,9 @@ size_t curlHeaderCallback(void* data, size_t size, size_t nmemb, void* user_data
432 return n; 432 return n;
433} 433}
434 434
435void LLCurl::Easy::prepRequest(const std::string& url, ResponderPtr responder, bool post) 435void LLCurl::Easy::prepRequest(const std::string& url,
436 const std::vector<std::string>& headers,
437 ResponderPtr responder, bool post)
436{ 438{
437 resetState(); 439 resetState();
438 440
@@ -465,8 +467,13 @@ void LLCurl::Easy::prepRequest(const std::string& url, ResponderPtr responder, b
465 { 467 {
466 slist_append("Connection: keep-alive"); 468 slist_append("Connection: keep-alive");
467 slist_append("Keep-alive: 300"); 469 slist_append("Keep-alive: 300");
470 // Accept and other headers
471 for (std::vector<std::string>::const_iterator iter = headers.begin();
472 iter != headers.end(); ++iter)
473 {
474 slist_append((*iter).c_str());
475 }
468 } 476 }
469 // *FIX: should have ACCEPT headers
470} 477}
471 478
472//////////////////////////////////////////////////////////////////////////// 479////////////////////////////////////////////////////////////////////////////
@@ -676,15 +683,18 @@ LLCurlRequest::LLCurlRequest() :
676 mActiveMulti(NULL), 683 mActiveMulti(NULL),
677 mActiveRequestCount(0) 684 mActiveRequestCount(0)
678{ 685{
686 mThreadID = LLThread::currentID();
679} 687}
680 688
681LLCurlRequest::~LLCurlRequest() 689LLCurlRequest::~LLCurlRequest()
682{ 690{
691 llassert_always(mThreadID == LLThread::currentID());
683 for_each(mMultiSet.begin(), mMultiSet.end(), DeletePointer()); 692 for_each(mMultiSet.begin(), mMultiSet.end(), DeletePointer());
684} 693}
685 694
686void LLCurlRequest::addMulti() 695void LLCurlRequest::addMulti()
687{ 696{
697 llassert_always(mThreadID == LLThread::currentID());
688 LLCurl::Multi* multi = new LLCurl::Multi(); 698 LLCurl::Multi* multi = new LLCurl::Multi();
689 mMultiSet.insert(multi); 699 mMultiSet.insert(multi);
690 mActiveMulti = multi; 700 mActiveMulti = multi;
@@ -714,17 +724,20 @@ bool LLCurlRequest::addEasy(LLCurl::Easy* easy)
714 724
715void LLCurlRequest::get(const std::string& url, LLCurl::ResponderPtr responder) 725void LLCurlRequest::get(const std::string& url, LLCurl::ResponderPtr responder)
716{ 726{
717 getByteRange(url, 0, -1, responder); 727 getByteRange(url, headers_t(), 0, -1, responder);
718} 728}
719 729
720bool LLCurlRequest::getByteRange(const std::string& url, S32 offset, S32 length, LLCurl::ResponderPtr responder) 730bool LLCurlRequest::getByteRange(const std::string& url,
731 const headers_t& headers,
732 S32 offset, S32 length,
733 LLCurl::ResponderPtr responder)
721{ 734{
722 LLCurl::Easy* easy = allocEasy(); 735 LLCurl::Easy* easy = allocEasy();
723 if (!easy) 736 if (!easy)
724 { 737 {
725 return false; 738 return false;
726 } 739 }
727 easy->prepRequest(url, responder); 740 easy->prepRequest(url, headers, responder);
728 easy->setopt(CURLOPT_HTTPGET, 1); 741 easy->setopt(CURLOPT_HTTPGET, 1);
729 if (length > 0) 742 if (length > 0)
730 { 743 {
@@ -736,14 +749,17 @@ bool LLCurlRequest::getByteRange(const std::string& url, S32 offset, S32 length,
736 return res; 749 return res;
737} 750}
738 751
739bool LLCurlRequest::post(const std::string& url, const LLSD& data, LLCurl::ResponderPtr responder) 752bool LLCurlRequest::post(const std::string& url,
753 const headers_t& headers,
754 const LLSD& data,
755 LLCurl::ResponderPtr responder)
740{ 756{
741 LLCurl::Easy* easy = allocEasy(); 757 LLCurl::Easy* easy = allocEasy();
742 if (!easy) 758 if (!easy)
743 { 759 {
744 return false; 760 return false;
745 } 761 }
746 easy->prepRequest(url, responder); 762 easy->prepRequest(url, headers, responder);
747 763
748 LLSDSerialize::toXML(data, easy->getInput()); 764 LLSDSerialize::toXML(data, easy->getInput());
749 S32 bytes = easy->getInput().str().length(); 765 S32 bytes = easy->getInput().str().length();
@@ -763,6 +779,7 @@ bool LLCurlRequest::post(const std::string& url, const LLSD& data, LLCurl::Respo
763// Note: call once per frame 779// Note: call once per frame
764S32 LLCurlRequest::process() 780S32 LLCurlRequest::process()
765{ 781{
782 llassert_always(mThreadID == LLThread::currentID());
766 S32 res = 0; 783 S32 res = 0;
767 for (curlmulti_set_t::iterator iter = mMultiSet.begin(); 784 for (curlmulti_set_t::iterator iter = mMultiSet.begin();
768 iter != mMultiSet.end(); ) 785 iter != mMultiSet.end(); )
@@ -782,6 +799,7 @@ S32 LLCurlRequest::process()
782 799
783S32 LLCurlRequest::getQueued() 800S32 LLCurlRequest::getQueued()
784{ 801{
802 llassert_always(mThreadID == LLThread::currentID());
785 S32 queued = 0; 803 S32 queued = 0;
786 for (curlmulti_set_t::iterator iter = mMultiSet.begin(); 804 for (curlmulti_set_t::iterator iter = mMultiSet.begin();
787 iter != mMultiSet.end(); ) 805 iter != mMultiSet.end(); )
diff --git a/linden/indra/llmessage/llcurl.h b/linden/indra/llmessage/llcurl.h
index ff63904..3e9c0d4 100644
--- a/linden/indra/llmessage/llcurl.h
+++ b/linden/indra/llmessage/llcurl.h
@@ -188,12 +188,14 @@ namespace boost
188class LLCurlRequest 188class LLCurlRequest
189{ 189{
190public: 190public:
191 typedef std::vector<std::string> headers_t;
192
191 LLCurlRequest(); 193 LLCurlRequest();
192 ~LLCurlRequest(); 194 ~LLCurlRequest();
193 195
194 void get(const std::string& url, LLCurl::ResponderPtr responder); 196 void get(const std::string& url, LLCurl::ResponderPtr responder);
195 bool getByteRange(const std::string& url, S32 offset, S32 length, LLCurl::ResponderPtr responder); 197 bool getByteRange(const std::string& url, const headers_t& headers, S32 offset, S32 length, LLCurl::ResponderPtr responder);
196 bool post(const std::string& url, const LLSD& data, LLCurl::ResponderPtr responder); 198 bool post(const std::string& url, const headers_t& headers, const LLSD& data, LLCurl::ResponderPtr responder);
197 S32 process(); 199 S32 process();
198 S32 getQueued(); 200 S32 getQueued();
199 201
@@ -207,6 +209,7 @@ private:
207 curlmulti_set_t mMultiSet; 209 curlmulti_set_t mMultiSet;
208 LLCurl::Multi* mActiveMulti; 210 LLCurl::Multi* mActiveMulti;
209 S32 mActiveRequestCount; 211 S32 mActiveRequestCount;
212 U32 mThreadID; // debug
210}; 213};
211 214
212class LLCurlEasyRequest 215class LLCurlEasyRequest
diff --git a/linden/indra/llmessage/llhttpclient.cpp b/linden/indra/llmessage/llhttpclient.cpp
index 4c466c5..23d9529 100644
--- a/linden/indra/llmessage/llhttpclient.cpp
+++ b/linden/indra/llmessage/llhttpclient.cpp
@@ -161,9 +161,10 @@ namespace
161 fstream.seekg(0, std::ios::end); 161 fstream.seekg(0, std::ios::end);
162 U32 fileSize = fstream.tellg(); 162 U32 fileSize = fstream.tellg();
163 fstream.seekg(0, std::ios::beg); 163 fstream.seekg(0, std::ios::beg);
164 std::vector<char> fileBuffer(fileSize); 164 char* fileBuffer;
165 fstream.read(&fileBuffer[0], fileSize); 165 fileBuffer = new char [fileSize];
166 ostream.write(&fileBuffer[0], fileSize); 166 fstream.read(fileBuffer, fileSize);
167 ostream.write(fileBuffer, fileSize);
167 fstream.close(); 168 fstream.close();
168 eos = true; 169 eos = true;
169 return STATUS_DONE; 170 return STATUS_DONE;
@@ -190,9 +191,10 @@ namespace
190 191
191 LLVFile vfile(gVFS, mUUID, mAssetType, LLVFile::READ); 192 LLVFile vfile(gVFS, mUUID, mAssetType, LLVFile::READ);
192 S32 fileSize = vfile.getSize(); 193 S32 fileSize = vfile.getSize();
193 std::vector<U8> fileBuffer(fileSize); 194 U8* fileBuffer;
194 vfile.read(&fileBuffer[0], fileSize); 195 fileBuffer = new U8 [fileSize];
195 ostream.write((char*)&fileBuffer[0], fileSize); 196 vfile.read(fileBuffer, fileSize);
197 ostream.write((char*)fileBuffer, fileSize);
196 eos = true; 198 eos = true;
197 return STATUS_DONE; 199 return STATUS_DONE;
198 } 200 }