diff options
author | Jacek Antonelli | 2010-02-08 19:01:20 -0600 |
---|---|---|
committer | Jacek Antonelli | 2010-02-08 19:01:20 -0600 |
commit | e7b590f6c90cefac0861a906523c398613ad1321 (patch) | |
tree | 73e7f88f726ca3ae3bbbeeed38874ef8f8538aa0 /linden/indra/llmessage/llcurl.cpp | |
parent | Ported some thread changes from Snowglobe. (diff) | |
download | meta-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.cpp | 34 |
1 files changed, 26 insertions, 8 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 | ||
435 | void LLCurl::Easy::prepRequest(const std::string& url, ResponderPtr responder, bool post) | 435 | void 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 | ||
681 | LLCurlRequest::~LLCurlRequest() | 689 | LLCurlRequest::~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 | ||
686 | void LLCurlRequest::addMulti() | 695 | void 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 | ||
715 | void LLCurlRequest::get(const std::string& url, LLCurl::ResponderPtr responder) | 725 | void 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 | ||
720 | bool LLCurlRequest::getByteRange(const std::string& url, S32 offset, S32 length, LLCurl::ResponderPtr responder) | 730 | bool 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 | ||
739 | bool LLCurlRequest::post(const std::string& url, const LLSD& data, LLCurl::ResponderPtr responder) | 752 | bool 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 |
764 | S32 LLCurlRequest::process() | 780 | S32 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 | ||
783 | S32 LLCurlRequest::getQueued() | 800 | S32 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(); ) |