Ejemplo n.º 1
0
void LLChangeChannel::operator()(LLSegment& segment)
{
    if(segment.isOnChannel(mIs))
    {
        segment.setChannel(mBecomes);
    }
}
Ejemplo n.º 2
0
	void buffer_object_t::test<2>()
	{
		LLSegment segment;
		ensure("LLSegment get functions failed", (0 == segment.getChannel() && NULL == segment.data() && 0 == segment.size()));
		segment.setChannel(50);
		ensure_equals("LLSegment setChannel() function failed", segment.getChannel(), 50);
		ensure("LLSegment isOnChannel() function failed", (TRUE == segment.isOnChannel(50)));
	}	
// virtual
int LLBufferStreamBuf::underflow()
{
	LLMemType m1(LLMemType::MTYPE_IO_BUFFER);
	//lldebugs << "LLBufferStreamBuf::underflow()" << llendl;
	if(!mBuffer)
	{
		return EOF;
	}

	LLMutexLock lock(mBuffer->getMutex());
	LLBufferArray::segment_iterator_t iter;
	LLBufferArray::segment_iterator_t end = mBuffer->endSegment();
	U8* last_pos = (U8*)gptr();
	LLSegment segment;
	if(last_pos)
	{
		// Back up into a piece of memory we know that we have
		// allocated so that calls for the next segment based on
		// 'after' will succeed.
		--last_pos;
		iter = mBuffer->splitAfter(last_pos);
		if(iter != end)
		{
			// We need to clear the read segment just in case we have
			// an early exit in the function and never collect the
			// next segment. Calling eraseSegment() with the same
			// segment twice is just like double deleting -- nothing
			// good comes from it.
			mBuffer->eraseSegment(iter++);
			if(iter != end) segment = (*iter);
		}
		else
		{
			// This should never really happen, but somehow, the
			// istream is telling the buf that it just finished
			// reading memory that is not in the buf. I think this
			// would only happen if there were a bug in the c++ stream
			// class. Just bail.
			// *TODO: can we set the fail bit on the stream somehow?
			return EOF;
		}
	}
	else
	{
		// Get iterator to full segment containing last_pos
		// and construct sub-segment starting at last_pos.
		// Note: segment may != *it at this point
		iter = mBuffer->constructSegmentAfter(last_pos, segment);
	}
	if(iter == end)
	{
		return EOF;
	}

	// Iterate through segments to find a non-empty segment on input channel.
	while((!segment.isOnChannel(mChannels.in()) || (segment.size() == 0)))
	{
		++iter;
		if(iter == end)
		{
			return EOF;
		}

		segment = *(iter);
	}

	// set up the stream to read from the next segment.
	char* start = (char*)segment.data();
	setg(start, start, start + segment.size());
	return *gptr();
}