Ejemplo n.º 1
0
bool FrameQueue::handleFrame(Connection::Ptr pConnection, Frame::Ptr pFrame)
{
	poco_assert_dbg (pConnection == _pConnection);

	if ((_frameType == 0 || pFrame->type() == _frameType) && pFrame->channel() == _channel)
	{
		{
			Poco::FastMutex::ScopedLock lock(_mutex);
			int rounds = 0;
			while (_queue.size() == MAX_QUEUE_SIZE && rounds < 100)
			{
				Poco::ScopedUnlock<Poco::FastMutex> unlock(_mutex);
				Poco::Thread::sleep(5);
				rounds++;
			}
			if (_queue.size() < MAX_QUEUE_SIZE)
			{
				_queue.push_back(pFrame);
				_sema.set();
				return true;
			}
		}
	}
	return false;
}
Ejemplo n.º 2
0
	bool handleFrame(Connection::Ptr pConnection, Frame::Ptr pFrame)
	{
		if (pFrame->type() == Frame::FRAME_TYPE_REQU && (pFrame->flags() & Frame::FRAME_FLAG_CONT) == 0)
		{
			Poco::SharedPtr<ChannelInputStream> pRequestStream = new ChannelInputStream(pConnection, pFrame->type(), pFrame->channel(), _pListener->getTimeout());
			Poco::SharedPtr<ChannelOutputStream> pReplyStream;
			if ((pFrame->flags() & Frame::FRAME_FLAG_ONEWAY) == 0)
			{
				Poco::UInt16 flags(0);
				if (pFrame->flags() & Frame::FRAME_FLAG_DEFLATE)
					flags |= Frame::FRAME_FLAG_DEFLATE;
				pReplyStream = new ChannelOutputStream(pConnection, Frame::FRAME_TYPE_REPL, pFrame->channel(), flags);
			}
			ServerTransport::Ptr pServerTransport = new ServerTransport(*_pListener, pRequestStream, pReplyStream, (pFrame->flags() & Frame::FRAME_FLAG_DEFLATE) != 0);
			_pListener->connectionManager().threadPool().start(*pServerTransport);
			Poco::Thread::yield();
			pServerTransport->waitReady();
			pRequestStream->rdbuf()->queue()->handleFrame(pConnection, pFrame);
			return true;
		}
		else return false;
	}