llcorehttpretryqueue.h 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. /**
  2. * @file llcorehttpretryqueue.h
  3. * @brief Internal declaration for the operation retry queue
  4. *
  5. * $LicenseInfo:firstyear=2012&license=viewerlgpl$
  6. * Second Life Viewer Source Code
  7. * Copyright (C) 2012, Linden Research, Inc.
  8. *
  9. * This library is free software; you can redistribute it and/or
  10. * modify it under the terms of the GNU Lesser General Public
  11. * License as published by the Free Software Foundation;
  12. * version 2.1 of the License only.
  13. *
  14. * This library is distributed in the hope that it will be useful,
  15. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  16. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  17. * Lesser General Public License for more details.
  18. *
  19. * You should have received a copy of the GNU Lesser General Public
  20. * License along with this library; if not, write to the Free Software
  21. * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  22. *
  23. * Linden Research, Inc., 945 Battery Street, San Francisco, CA 94111 USA
  24. * $/LicenseInfo$
  25. */
  26. #ifndef _LLCORE_HTTP_RETRY_QUEUE_H_
  27. #define _LLCORE_HTTP_RETRY_QUEUE_H_
  28. #include <queue>
  29. #include "llcorehttpoprequest.h"
  30. namespace LLCore
  31. {
  32. // HttpRetryQueue provides a simple priority queue for HttpOpRequest objects.
  33. //
  34. // This uses the priority_queue adaptor class to provide the queue as well as
  35. // the ordering scheme while allowing us access to the raw container if we
  36. // follow a few simple rules. One of the more important of those rules is that
  37. // any iterator becomes invalid on element erasure. So pay attention.
  38. //
  39. // Threading: not thread-safe. Expected to be used entirely by a single thread,
  40. // typically a worker thread of some sort.
  41. struct HttpOpRetryCompare
  42. {
  43. LL_INLINE bool operator()(const HttpOpRequest::ptr_t& lhs,
  44. const HttpOpRequest::ptr_t& rhs)
  45. {
  46. return lhs->mPolicyRetryAt < rhs->mPolicyRetryAt;
  47. }
  48. };
  49. typedef std::priority_queue<HttpOpRequest::ptr_t,
  50. std::deque<HttpOpRequest::ptr_t>,
  51. LLCore::HttpOpRetryCompare> HttpRetryQueueBase;
  52. class HttpRetryQueue final : public HttpRetryQueueBase
  53. {
  54. public:
  55. HttpRetryQueue() = default;
  56. HttpRetryQueue(const HttpRetryQueue&) = delete;
  57. void operator=(const HttpRetryQueue&) = delete;
  58. LL_INLINE const container_type& get_container() const { return c; }
  59. LL_INLINE container_type& get_container() { return c; }
  60. };
  61. } // End namespace LLCore
  62. #endif // _LLCORE_HTTP_RETRY_QUEUE_H_