PageRenderTime 24ms CodeModel.GetById 12ms app.highlight 8ms RepoModel.GetById 2ms 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
  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
 28#ifndef LL_LLPACKETRING_H
 29#define LL_LLPACKETRING_H
 30
 31#include <queue>
 32
 33#include "llhost.h"
 34#include "llpacketbuffer.h"
 35#include "llproxy.h"
 36#include "llthrottle.h"
 37#include "net.h"
 38
 39class LLPacketRing
 40{
 41public:
 42	LLPacketRing();         
 43    ~LLPacketRing();
 44
 45	void cleanup();
 46
 47	void dropPackets(U32);	
 48	void setDropPercentage (F32 percent_to_drop);
 49	void setUseInThrottle(const BOOL use_throttle);
 50	void setUseOutThrottle(const BOOL use_throttle);
 51	void setInBandwidth(const F32 bps);
 52	void setOutBandwidth(const F32 bps);
 53	S32  receivePacket (S32 socket, char *datap);
 54	S32  receiveFromRing (S32 socket, char *datap);
 55
 56	BOOL sendPacket(int h_socket, char * send_buffer, S32 buf_size, LLHost host);
 57
 58	inline LLHost getLastSender();
 59	inline LLHost getLastReceivingInterface();
 60
 61	S32 getAndResetActualInBits()				{ S32 bits = mActualBitsIn; mActualBitsIn = 0; return bits;}
 62	S32 getAndResetActualOutBits()				{ S32 bits = mActualBitsOut; mActualBitsOut = 0; return bits;}
 63protected:
 64	BOOL mUseInThrottle;
 65	BOOL mUseOutThrottle;
 66	
 67	// For simulating a lower-bandwidth connection - BPS
 68	LLThrottle mInThrottle;
 69	LLThrottle mOutThrottle;
 70
 71	S32 mActualBitsIn;
 72	S32 mActualBitsOut;
 73	S32 mMaxBufferLength;			// How much data can we queue up before dropping data.
 74	S32 mInBufferLength;			// Current incoming buffer length
 75	S32 mOutBufferLength;			// Current outgoing buffer length
 76
 77	F32 mDropPercentage;			// % of packets to drop
 78	U32 mPacketsToDrop;				// drop next n packets
 79
 80	std::queue<LLPacketBuffer *> mReceiveQueue;
 81	std::queue<LLPacketBuffer *> mSendQueue;
 82
 83	LLHost mLastSender;
 84	LLHost mLastReceivingIF;
 85
 86private:
 87	BOOL sendPacketImpl(int h_socket, const char * send_buffer, S32 buf_size, LLHost host);
 88};
 89
 90
 91inline LLHost LLPacketRing::getLastSender()
 92{
 93	return mLastSender;
 94}
 95
 96inline LLHost LLPacketRing::getLastReceivingInterface()
 97{
 98	return mLastReceivingIF;
 99}
100
101#endif