llcorehttppolicyclass.cpp 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128
  1. /**
  2. * @file llcorehttppolicyclass.cpp
  3. * @brief Definitions for internal class defining class policy option.
  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. #include "linden_common.h"
  27. #include "llcorehttpinternal.h"
  28. #include "llcorehttppolicyclass.h"
  29. namespace LLCore
  30. {
  31. HttpPolicyClass::HttpPolicyClass()
  32. : mConnectionLimit(HTTP_CONNECTION_LIMIT_DEFAULT),
  33. mPerHostConnectionLimit(HTTP_CONNECTION_LIMIT_DEFAULT),
  34. mPipelining(HTTP_PIPELINING_DEFAULT),
  35. mThrottleRate(HTTP_THROTTLE_RATE_DEFAULT),
  36. mTrace(0L)
  37. {
  38. }
  39. HttpPolicyClass& HttpPolicyClass::operator=(const HttpPolicyClass& other)
  40. {
  41. if (this != &other)
  42. {
  43. mConnectionLimit = other.mConnectionLimit;
  44. mPerHostConnectionLimit = other.mPerHostConnectionLimit;
  45. mPipelining = other.mPipelining;
  46. mThrottleRate = other.mThrottleRate;
  47. mTrace = other.mTrace;
  48. }
  49. return *this;
  50. }
  51. HttpPolicyClass::HttpPolicyClass(const HttpPolicyClass& other)
  52. : mConnectionLimit(other.mConnectionLimit),
  53. mPerHostConnectionLimit(other.mPerHostConnectionLimit),
  54. mPipelining(other.mPipelining),
  55. mThrottleRate(other.mThrottleRate),
  56. mTrace(other.mTrace)
  57. {
  58. }
  59. HttpStatus HttpPolicyClass::set(HttpRequest::EPolicyOption opt, long value)
  60. {
  61. switch (opt)
  62. {
  63. case HttpRequest::PO_CONNECTION_LIMIT:
  64. mConnectionLimit = llclamp(value, long(HTTP_CONNECTION_LIMIT_MIN),
  65. long(HTTP_CONNECTION_LIMIT_MAX));
  66. break;
  67. case HttpRequest::PO_PER_HOST_CONNECTION_LIMIT:
  68. mPerHostConnectionLimit = llclamp(value,
  69. long(HTTP_CONNECTION_LIMIT_MIN),
  70. mConnectionLimit);
  71. break;
  72. case HttpRequest::PO_PIPELINING_DEPTH:
  73. mPipelining = llclamp(value, 0L, HTTP_PIPELINING_MAX);
  74. break;
  75. case HttpRequest::PO_THROTTLE_RATE:
  76. mThrottleRate = llclamp(value, 0L, 1000000L);
  77. break;
  78. case HttpRequest::PO_TRACE:
  79. mTrace = llclamp(value, HTTP_TRACE_MIN, HTTP_TRACE_MAX);
  80. break;
  81. default:
  82. return HttpStatus(HttpStatus::LLCORE, HE_INVALID_ARG);
  83. }
  84. return HttpStatus();
  85. }
  86. HttpStatus HttpPolicyClass::get(HttpRequest::EPolicyOption opt,
  87. long* value) const
  88. {
  89. switch (opt)
  90. {
  91. case HttpRequest::PO_CONNECTION_LIMIT:
  92. *value = mConnectionLimit;
  93. break;
  94. case HttpRequest::PO_PER_HOST_CONNECTION_LIMIT:
  95. *value = mPerHostConnectionLimit;
  96. break;
  97. case HttpRequest::PO_PIPELINING_DEPTH:
  98. *value = mPipelining;
  99. break;
  100. case HttpRequest::PO_THROTTLE_RATE:
  101. *value = mThrottleRate;
  102. break;
  103. default:
  104. return HttpStatus(HttpStatus::LLCORE, HE_INVALID_ARG);
  105. }
  106. return HttpStatus();
  107. }
  108. } // End namespace LLCore