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); }
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*/ }
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; }
/*------------------------------------------------------------------*\ 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(); } }
// *************************************************************************** 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; }