Exemplo n.º 1
0
	void CFileReceiver::_dealWithReceivedFile(TProxyPtr sender,TFileRequestPtr theRequest,const NLNET::TBinBuffer& data)
	{
		// log progress..
		_clearDownloadLog(theRequest->FileName);
		_log("receivedFile: "+theRequest->FileName+NLMISC::toString("(%d bytes)",data.getBufferSize()));

		// call the user callback for the file data
		NLMISC::CMemStream memStream;
		memStream.fill(data.getBuffer(),data.getBufferSize());
		memStream.invert();
		cbFileDownloadSuccess(theRequest->FileName,memStream);

		// look for the proxy record for the emitter
		TProxies::iterator pit= _Proxies.find(sender);
		BOMB_IF(pit==_Proxies.end(),"ERROR: Failed to identify the sender for the received file: "+theRequest->FileName,return);

		// liberate this request
		for (TFileRequests::iterator fit=_FileRequests.begin(); fit!=_FileRequests.end();++fit)
		{
			if (*fit==theRequest)
			{
				_FileRequests.erase(fit);
				break;
			}
		}

		// cleanup the emitter
		pit->second.CurrentRequest= NULL;

		// look for a new job for the sender
		_lookForNewJob(pit->second);
	}
Exemplo n.º 2
0
void CBufFIFO::front (NLMISC::CMemStream &buffer)
{
	uint8 *tmpbuffer;
	uint32 s;

	buffer.clear ();

	front (tmpbuffer, s);

	buffer.fill (tmpbuffer, s);

	/*
	TTicks before = CTime::getPerformanceTime ();

	uint8	*tail = _Tail;

	buffer.clear ();

	if (empty ())
	{
		nlwarning("Try to get the front of an empty fifo!");
		return;
	}

	_Fronted++;

	if (_Rewinder != NULL && tail == _Rewinder)
	{
#if DEBUG_FIFO
		nldebug("%p front rewind!", this);
#endif

		// need to rewind
		tail = _Buffer;
	}

	TFifoSize size = *(TFifoSize *)tail;

#if DEBUG_FIFO
	nldebug("%p front(%d)", this, size);
#endif

	tail += sizeof (TFifoSize);

	//buffer.resize (size);
	//CFastMem::memcpy (&(buffer[0]), tail, size);

	buffer.fill (tail, size);

	// stat code
	TTicks after = CTime::getPerformanceTime ();
	_FrontedTime += after - before;

#if DEBUG_FIFO
	display ();
#endif*/
}
Exemplo n.º 3
0
CWriteFile::CWriteFile(const std::string& filename, const TRequester &requester, uint32 requestid, NLMISC::CMemStream& data)
	: IFileAccess(filename, requester, requestid)
{
	BackupFile = false;
	Append = false;
	CreateDir = true;
	FailureMode = MajorFailureMode;
	uint32 startPos = (uint32)data.getPos();
	uint32 actualLen = data.length()-startPos;
	Data.resize(actualLen);
	memcpy(&(Data[0]), data.buffer()+startPos, actualLen);
}
Exemplo n.º 4
0
static T	*DupSerializable(const T *in) throw(NLMISC::EStream)
{
	NLMISC::CMemStream ms;
	nlassert(!ms.isReading());
	T *nonConstIn = const_cast<T *>(in);
	TSerializePolicy::serial(nonConstIn, ms);
	std::vector<uint8> datas(ms.length());
	std::copy(ms.buffer(), ms.buffer() + ms.length(), datas.begin());
	ms.resetPtrTable();
	ms.invert();
	ms.fill(&datas[0], (uint)datas.size());
	nlassert(ms.isReading());
	T *newObj = NULL;
	TSerializePolicy::serial(newObj, ms);
	return newObj;
}
Exemplo n.º 5
0
/*------------------------------------------------------------------*\
							doGenerate()
\*------------------------------------------------------------------*/
void CTextureMem::doGenerate(bool /* async */)
{
	if (_Data)
	{
		if (_IsFile)
		{
			NLMISC::CMemStream m (true);
			m.fill (_Data, _Length);
			load (m);
		}
		else
		{
			resize(_TexWidth, _TexHeight, _TexType);
			::memcpy(&getPixels(0)[0], _Data, _Length);
			buildMipMaps();
		}
	}
	else
	{
		makeDummy();
	}
}
Exemplo n.º 6
0
void	CLogAnalyserService::updateWebConnection()
{

	nlassert(WebServer != NULL);

	try
	{
		WebServer->update ();

		while (WebServer->dataAvailable ())
		{
			// create a string mem stream to easily communicate with web server
			NLMISC::CMemStream msgin (true);
			TSockId		host;
			bool		success = false;
			std::string	reason;

			try
			{
				WebServer->receive (msgin, &host);

				uint32	fake = 0;
				msgin.serial(fake);

				uint8	messageType = 0xff;
				msgin.serial (messageType);

				if(messageType<sizeof(WebCallbackArray)/sizeof(WebCallbackArray[0]))
				{
					WebCallbackArray[messageType](msgin, host);
					success = true;
				}
				else
				{
					reason = "unknown command "+toString(messageType);
				}
			}
			catch (Exception &e)
			{
				nlwarning ("Error during receiving: '%s'", e.what ());
				reason = e.what();
			}

			if(!success)
			{
				nlwarning ("Failed to decode Web command");

				CMemStream	msgout;
				uint32		fake = 0;
				msgout.serial(fake);

				std::string	result = "0:Failed to decode command";
				if (!reason.empty())
					result += " ("+reason+")";
				msgout.serial (result);
				WebServer->send (msgout, host);
			}
		}
	}
	catch (Exception &e)
	{
		nlwarning ("Error during update: '%s'", e.what ());
	}
}
Exemplo n.º 7
0
	// ***************************************************************************
	CInterfaceElement *CInterfaceElement::clone()
	{
		NLMISC::CMemStream dupStream;
		nlassert(!dupStream.isReading());
		CInterfaceGroup *oldParent = _Parent;
		_Parent = NULL;
		CInterfaceElement *oldParentPos = _ParentPos;
		CInterfaceElement *oldParentSize = _ParentSize;
		if (_ParentPos == oldParent) _ParentPos = NULL;
		if (_ParentSize == oldParent) _ParentSize = NULL;
		CInterfaceElement *begunThisCloneWarHas = NULL;
		try
		{
			if (dupStream.isReading())
			{
				dupStream.invert();
			}
			CInterfaceElement *self = this;
			dupStream.serialPolyPtr(self);
			std::vector<uint8> datas(dupStream.length());
			std::copy(dupStream.buffer(), dupStream.buffer() + dupStream.length(), datas.begin());
			dupStream.resetPtrTable();
			dupStream.invert();
			dupStream.fill(&datas[0], (uint32)datas.size());
			dupStream.serialPolyPtr(begunThisCloneWarHas);
		}
		catch(const NLMISC::EStream &)
		{
			// no-op -> caller has to handle the failure because NULL will be returned
		}
		//
		_Parent		  = oldParent;
		_ParentPos	  = oldParentPos;
		_ParentSize	  = oldParentSize;
		//
		return begunThisCloneWarHas;
	}