llpacketring.h 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109
  1. /**
  2. * @file llpacketring.h
  3. * @brief definition of LLPacketRing class for implementing a resend,
  4. * drop, or delay in packet transmissions
  5. *
  6. * $LicenseInfo:firstyear=2001&license=viewergpl$
  7. *
  8. * Copyright (c) 2001-2009, Linden Research, Inc.
  9. *
  10. * Second Life Viewer Source Code
  11. * The source code in this file ("Source Code") is provided by Linden Lab
  12. * to you under the terms of the GNU General Public License, version 2.0
  13. * ("GPL"), unless you have obtained a separate licensing agreement
  14. * ("Other License"), formally executed by you and Linden Lab. Terms of
  15. * the GPL can be found in doc/GPL-license.txt in this distribution, or
  16. * online at http://secondlifegrid.net/programs/open_source/licensing/gplv2
  17. *
  18. * There are special exceptions to the terms and conditions of the GPL as
  19. * it is applied to this Source Code. View the full text of the exception
  20. * in the file doc/FLOSS-exception.txt in this software distribution, or
  21. * online at
  22. * http://secondlifegrid.net/programs/open_source/licensing/flossexception
  23. *
  24. * By copying, modifying or distributing this software, you acknowledge
  25. * that you have read and understood your obligations described above,
  26. * and agree to abide by those obligations.
  27. *
  28. * ALL LINDEN LAB SOURCE CODE IS PROVIDED "AS IS." LINDEN LAB MAKES NO
  29. * WARRANTIES, EXPRESS, IMPLIED OR OTHERWISE, REGARDING ITS ACCURACY,
  30. * COMPLETENESS OR PERFORMANCE.
  31. * $/LicenseInfo$
  32. */
  33. #ifndef LL_LLPACKETRING_H
  34. #define LL_LLPACKETRING_H
  35. #include <queue>
  36. #include "llhost.h"
  37. #include "llthrottle.h"
  38. class LLPacketBuffer;
  39. class LLPacketRing
  40. {
  41. protected:
  42. LOG_CLASS(LLPacketRing);
  43. public:
  44. LLPacketRing();
  45. ~LLPacketRing();
  46. void cleanup();
  47. LL_INLINE void setUseInThrottle(bool b) { mUseInThrottle = b; }
  48. LL_INLINE void setUseOutThrottle(bool b) { mUseOutThrottle = b; }
  49. LL_INLINE void setInBandwidth(F32 bps) { mInThrottle.setRate(bps); }
  50. LL_INLINE void setOutBandwidth(F32 bps) { mOutThrottle.setRate(bps); }
  51. S32 receivePacket(S32 socket, char* datap);
  52. S32 receiveFromRing(S32 socket, char* datap);
  53. bool sendPacket(int h_socket, char* send_buffer, S32 buf_size, LLHost host);
  54. LL_INLINE LLHost getLastSender() { return mLastSender; }
  55. LL_INLINE LLHost getLastReceivingInterface() { return mLastReceivingIF; }
  56. LL_INLINE S32 getAndResetActualInBits()
  57. {
  58. S32 bits = mActualBitsIn;
  59. mActualBitsIn = 0;
  60. return bits;
  61. }
  62. LL_INLINE S32 getAndResetActualOutBits()
  63. {
  64. S32 bits = mActualBitsOut;
  65. mActualBitsOut = 0;
  66. return bits;
  67. }
  68. private:
  69. bool sendPacketImpl(int h_socket, const char* send_buffer, S32 buf_size,
  70. LLHost host);
  71. protected:
  72. typedef std::queue<LLPacketBuffer*> packet_queue_t;
  73. packet_queue_t mReceiveQueue;
  74. packet_queue_t mSendQueue;
  75. LLHost mLastSender;
  76. LLHost mLastReceivingIF;
  77. // For simulating a lower-bandwidth connection - BPS
  78. LLThrottle mInThrottle;
  79. LLThrottle mOutThrottle;
  80. S32 mActualBitsIn;
  81. S32 mActualBitsOut;
  82. // How much data can we queue up before dropping data.
  83. S32 mMaxBufferLength;
  84. S32 mInBufferLength; // Current incoming buffer length
  85. S32 mOutBufferLength; // Current outgoing buffer length
  86. bool mUseInThrottle;
  87. bool mUseOutThrottle;
  88. };
  89. #endif