PageRenderTime 156ms CodeModel.GetById 0ms RepoModel.GetById 0ms app.codeStats 0ms

/indra/llmessage/llpacketring.h

https://bitbucket.org/lindenlab/viewer-beta/
C++ Header | 101 lines | 55 code | 19 blank | 27 comment | 0 complexity | 5b1525d11757b355a026e08ef76b63d3 MD5 | raw file
Possible License(s): LGPL-2.1
  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=viewerlgpl$
  7. * Second Life Viewer Source Code
  8. * Copyright (C) 2010, Linden Research, Inc.
  9. *
  10. * This library is free software; you can redistribute it and/or
  11. * modify it under the terms of the GNU Lesser General Public
  12. * License as published by the Free Software Foundation;
  13. * version 2.1 of the License only.
  14. *
  15. * This library is distributed in the hope that it will be useful,
  16. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  17. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  18. * Lesser General Public License for more details.
  19. *
  20. * You should have received a copy of the GNU Lesser General Public
  21. * License along with this library; if not, write to the Free Software
  22. * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  23. *
  24. * Linden Research, Inc., 945 Battery Street, San Francisco, CA 94111 USA
  25. * $/LicenseInfo$
  26. */
  27. #ifndef LL_LLPACKETRING_H
  28. #define LL_LLPACKETRING_H
  29. #include <queue>
  30. #include "llhost.h"
  31. #include "llpacketbuffer.h"
  32. #include "llproxy.h"
  33. #include "llthrottle.h"
  34. #include "net.h"
  35. class LLPacketRing
  36. {
  37. public:
  38. LLPacketRing();
  39. ~LLPacketRing();
  40. void cleanup();
  41. void dropPackets(U32);
  42. void setDropPercentage (F32 percent_to_drop);
  43. void setUseInThrottle(const BOOL use_throttle);
  44. void setUseOutThrottle(const BOOL use_throttle);
  45. void setInBandwidth(const F32 bps);
  46. void setOutBandwidth(const F32 bps);
  47. S32 receivePacket (S32 socket, char *datap);
  48. S32 receiveFromRing (S32 socket, char *datap);
  49. BOOL sendPacket(int h_socket, char * send_buffer, S32 buf_size, LLHost host);
  50. inline LLHost getLastSender();
  51. inline LLHost getLastReceivingInterface();
  52. S32 getAndResetActualInBits() { S32 bits = mActualBitsIn; mActualBitsIn = 0; return bits;}
  53. S32 getAndResetActualOutBits() { S32 bits = mActualBitsOut; mActualBitsOut = 0; return bits;}
  54. protected:
  55. BOOL mUseInThrottle;
  56. BOOL mUseOutThrottle;
  57. // For simulating a lower-bandwidth connection - BPS
  58. LLThrottle mInThrottle;
  59. LLThrottle mOutThrottle;
  60. S32 mActualBitsIn;
  61. S32 mActualBitsOut;
  62. S32 mMaxBufferLength; // How much data can we queue up before dropping data.
  63. S32 mInBufferLength; // Current incoming buffer length
  64. S32 mOutBufferLength; // Current outgoing buffer length
  65. F32 mDropPercentage; // % of packets to drop
  66. U32 mPacketsToDrop; // drop next n packets
  67. std::queue<LLPacketBuffer *> mReceiveQueue;
  68. std::queue<LLPacketBuffer *> mSendQueue;
  69. LLHost mLastSender;
  70. LLHost mLastReceivingIF;
  71. private:
  72. BOOL sendPacketImpl(int h_socket, const char * send_buffer, S32 buf_size, LLHost host);
  73. };
  74. inline LLHost LLPacketRing::getLastSender()
  75. {
  76. return mLastSender;
  77. }
  78. inline LLHost LLPacketRing::getLastReceivingInterface()
  79. {
  80. return mLastReceivingIF;
  81. }
  82. #endif