PageRenderTime 15ms CodeModel.GetById 1ms app.highlight 10ms RepoModel.GetById 1ms app.codeStats 0ms

/indra/llmessage/lliobuffer.cpp

https://bitbucket.org/lindenlab/viewer-beta/
C++ | 114 lines | 72 code | 10 blank | 32 comment | 9 complexity | 3d3876ef214fb3c7dd49de228647d78d MD5 | raw file
  1/** 
  2 * @file lliobuffer.cpp
  3 * @author Phoenix
  4 * @date 2005-05-04
  5 * @brief Definition of buffer based implementations of IO Pipes.
  6 *
  7 * $LicenseInfo:firstyear=2005&license=viewerlgpl$
  8 * Second Life Viewer Source Code
  9 * Copyright (C) 2010, Linden Research, Inc.
 10 * 
 11 * This library is free software; you can redistribute it and/or
 12 * modify it under the terms of the GNU Lesser General Public
 13 * License as published by the Free Software Foundation;
 14 * version 2.1 of the License only.
 15 * 
 16 * This library is distributed in the hope that it will be useful,
 17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 19 * Lesser General Public License for more details.
 20 * 
 21 * You should have received a copy of the GNU Lesser General Public
 22 * License along with this library; if not, write to the Free Software
 23 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
 24 * 
 25 * Linden Research, Inc., 945 Battery Street, San Francisco, CA  94111  USA
 26 * $/LicenseInfo$
 27 */
 28
 29#include "linden_common.h"
 30#include "lliobuffer.h"
 31
 32//
 33// LLIOBuffer
 34//
 35LLIOBuffer::LLIOBuffer() :
 36	mBuffer(NULL),
 37	mBufferSize(0L),
 38	mReadHead(NULL),
 39	mWriteHead(NULL)
 40{
 41}
 42
 43LLIOBuffer::~LLIOBuffer()
 44{
 45	if(mBuffer)
 46	{
 47		delete[] mBuffer;
 48	}
 49}
 50
 51U8* LLIOBuffer::data() const
 52{
 53	return mBuffer;
 54}
 55
 56S64 LLIOBuffer::size() const
 57{
 58	return mBufferSize;
 59}
 60
 61U8* LLIOBuffer::current() const
 62{
 63	return mReadHead;
 64}
 65
 66S64 LLIOBuffer::bytesLeft() const
 67{
 68	return mWriteHead - mReadHead;
 69}
 70
 71void LLIOBuffer::clear()
 72{
 73	mReadHead = mBuffer;
 74	mWriteHead = mBuffer;
 75}
 76
 77LLIOPipe::EStatus LLIOBuffer::seek(LLIOBuffer::EHead head, S64 delta)
 78{
 79	LLIOPipe::EStatus status = STATUS_ERROR;
 80	switch(head)
 81	{
 82	case READ:
 83		if(((delta >= 0) && ((mReadHead + delta) <= mWriteHead))
 84		   || ((delta < 0) && ((mReadHead + delta) >= mBuffer)))
 85		{
 86			mReadHead += delta;
 87			status = STATUS_OK;
 88		}
 89		break;
 90	case WRITE:
 91		if(((delta >= 0) && ((mWriteHead + delta) < (mBuffer + mBufferSize)))
 92		   || ((delta < 0) && ((mWriteHead + delta) > mReadHead)))
 93		{
 94			mWriteHead += delta;
 95			status = STATUS_OK;
 96		}
 97	default:
 98		break;
 99	}
100	return status;
101}
102
103// virtual
104LLIOPipe::EStatus LLIOBuffer::process_impl(
105	const LLChannelDescriptors& channels,
106	buffer_ptr_t& buffer,
107	bool& eos,
108	LLSD& context,
109	LLPumpIO* pump)
110{
111	// no-op (I think)
112	llwarns << "You are using an LLIOBuffer which is deprecated." << llendl;
113	return STATUS_OK;
114}