00001 00033 #ifndef LL_LLPACKETRING_H 00034 #define LL_LLPACKETRING_H 00035 00036 #include <queue> 00037 00038 #include "llpacketbuffer.h" 00039 #include "llhost.h" 00040 #include "net.h" 00041 #include "llthrottle.h" 00042 00043 00044 class LLPacketRing 00045 { 00046 public: 00047 LLPacketRing(); 00048 ~LLPacketRing(); 00049 00050 void free(); 00051 00052 void dropPackets(U32); 00053 void setDropPercentage (F32 percent_to_drop); 00054 void setUseInThrottle(const BOOL use_throttle); 00055 void setUseOutThrottle(const BOOL use_throttle); 00056 void setInBandwidth(const F32 bps); 00057 void setOutBandwidth(const F32 bps); 00058 S32 receivePacket (S32 socket, char *datap); 00059 S32 receiveFromRing (S32 socket, char *datap); 00060 00061 BOOL sendPacket(int h_socket, char * send_buffer, S32 buf_size, LLHost host); 00062 00063 inline LLHost getLastSender(); 00064 00065 S32 getAndResetActualInBits() { S32 bits = mActualBitsIn; mActualBitsIn = 0; return bits;} 00066 S32 getAndResetActualOutBits() { S32 bits = mActualBitsOut; mActualBitsOut = 0; return bits;} 00067 protected: 00068 BOOL mUseInThrottle; 00069 BOOL mUseOutThrottle; 00070 00071 // For simulating a lower-bandwidth connection - BPS 00072 LLThrottle mInThrottle; 00073 LLThrottle mOutThrottle; 00074 00075 S32 mActualBitsIn; 00076 S32 mActualBitsOut; 00077 S32 mMaxBufferLength; // How much data can we queue up before dropping data. 00078 S32 mInBufferLength; // Current incoming buffer length 00079 S32 mOutBufferLength; // Current outgoing buffer length 00080 00081 F32 mDropPercentage; // % of packets to drop 00082 U32 mPacketsToDrop; // drop next n packets 00083 00084 std::queue<LLPacketBuffer *> mReceiveQueue; 00085 std::queue<LLPacketBuffer *> mSendQueue; 00086 00087 LLHost mLastSender; 00088 }; 00089 00090 00091 inline LLHost LLPacketRing::getLastSender() 00092 { 00093 return mLastSender; 00094 } 00095 00096 #endif