unsigned FillBufferByCom( ComEvaluator& evalutor , SBuffer& buffer , IComPacket* cp ) { bool done = false; int count = 1; unsigned result; while ( !done ) { try { result = ComEvaluator::fillBuffer( cp , buffer ); done = true; } catch ( BufferException& e ) { buffer.grow( ( buffer.getMaxSize() * 3 ) / 2 ); Msg( e.what() ); } catch ( ComException& e ) { Msg( e.what() ); return 0; } ++count; } return result; }
HRESULT GetTokenFromPublicKey(SBuffer &publicKeyBLOB, SBuffer &publicKeyTokenBLOB) { HRESULT hr = S_OK; BINDER_LOG_ENTER(W("GetTokenFromPublicKey")); const BYTE *pByteKey = publicKeyBLOB; DWORD dwKeyLen = publicKeyBLOB.GetSize(); BYTE *pByteToken = NULL; DWORD dwTokenLen = 0; if (!StrongNameTokenFromPublicKey(const_cast<BYTE *>(pByteKey), dwKeyLen, &pByteToken, &dwTokenLen)) { BINDER_LOG(W("StrongNameTokenFromPublicKey failed!")); IF_FAIL_GO(StrongNameErrorInfo()); } else { _ASSERTE(pByteToken != NULL); publicKeyTokenBLOB.Set(pByteToken, dwTokenLen); StrongNameFreeBuffer(pByteToken); } Exit: BINDER_LOG_LEAVE_HR(W("GetTokenFromPublicKey"), hr); return hr; }
bool EvalCommand( UdpChain& chain , ComEvaluator& evaluator , SBuffer& buffer , ComConnection* con /*= NULL */ ) { unsigned size; while( chain.readPacket( buffer , size ) ) { size_t oldSize = buffer.getAvailableSize(); if ( oldSize < size ) throw ComException( "error UDP Packet" ); do { if ( !evaluator.evalCommand( buffer , con ) ) { ::Msg( "readPacket Error Need Fix" ); return false; } } while( oldSize - buffer.getAvailableSize() < size ); if ( oldSize - buffer.getAvailableSize() != size ) throw ComException( "error UDP Packet" ); } return true; }
void Game::takeData( SBuffer& buffer ) { unsigned size = mStepVec.size(); buffer.fill( size ); for( int i = 0 ; i < mStepVec.size() ; ++i ) { StepInfo& info = mStepVec[i]; buffer.fill( info.idxPlay ); } }
void ZapImage::OutputInliningTableForReadyToRun() { SBuffer serializedInlineTrackingBuffer; m_pPreloader->GetSerializedInlineTrackingMap(&serializedInlineTrackingBuffer); ZapNode * pBlob = ZapBlob::NewAlignedBlob(this, (PVOID)(const BYTE*) serializedInlineTrackingBuffer, serializedInlineTrackingBuffer.GetSize(), 4); m_pDebugSection->Place(pBlob); GetReadyToRunHeader()->RegisterSection(READYTORUN_SECTION_INLINING_INFO, pBlob); }
bool Game::restoreData( SBuffer& buffer ) { mStepVec.clear(); restart(); unsigned size; buffer.take( size ); for( int i = 0 ; i < size ; ++i ) { int idxPos; buffer.take( idxPos ); if ( idxPos == -1 ) { pass(); } else if ( play( mBoard.getPos( idxPos ) ) ) { return false; } } return true; }
bool UdpChain::readPacket( SBuffer& buffer , unsigned& readSize ) { if ( !buffer.getAvailableSize() ) return false; uint32 incoming; uint32 outgoing; int count = 0; uint32 maxOutgoing = 0; while( buffer.getAvailableSize() ) { buffer.take( incoming ); buffer.take( outgoing ); buffer.take( readSize ); if ( maxOutgoing < outgoing ) maxOutgoing = outgoing; if ( incoming <= mIncomingAck ) { if ( readSize > buffer.getAvailableSize() ) { ::Msg( "UdpChain::error incoming data" ); return false; } { //::Msg( "UdpChain::old incoming data" ); buffer.shiftUseSize( readSize ); } } else if ( incoming > mIncomingAck ) { mIncomingAck = incoming; if ( readSize ) break; } ++count; } refrushReliableData( maxOutgoing ); //Msg( "readPacket %u %u %u" , outgoing , incoming , readSize ); return buffer.getAvailableSize() != 0; }
bool UdpChain::sendPacket( long time , TSocket& socket , SBuffer& buffer , NetAddress& addr ) { if ( buffer.getFillSize() == 0 && time - mTimeLastUpdate > mTimeResendRel ) { if ( mBufferRel.getFillSize() == 0 ) return false; } uint32 outgoing = ++mOutgoingSeq; uint32 incoming = mIncomingAck; uint32 bufSize = (uint32)buffer.getFillSize(); if ( bufSize ) { if ( mBufferRel.getFreeSize() < bufSize ) { mBufferRel.grow( mBufferRel.getMaxSize() * 2 ); Msg( "UDPChain::sendPacket : ReliableBuffer too small" ); } size_t oldSize = mBufferRel.getFillSize(); mBufferRel.fill( outgoing ); mBufferRel.fill( incoming ); mBufferRel.fill( bufSize ); mBufferRel.append( buffer ); checkBuffer( mBufferRel.getData() , (int)mBufferRel.getFillSize() ); DataInfo info; info.size = (uint32)( mBufferRel.getFillSize() - oldSize ); info.sequence = outgoing; mInfoList.push_back( info ); buffer.clear(); mOutgoingAck = outgoing; } mBufferCache.clear(); try { if ( mOutgoingRel < mOutgoingAck ) { mBufferCache.append( mBufferRel ); } else { mBufferCache.fill( outgoing ); mBufferCache.fill( incoming ); mBufferCache.fill( 0 ); } int count = 0; while( mBufferCache.getAvailableSize() ) { int numSend = mBufferCache.take( socket , addr ); ++count; if ( count == 10 ) { return false; } } mTimeLastUpdate = time; } catch ( BufferException& ) { mBufferCache.resize( mBufferCache.getMaxSize() * 2 ); return false; } //Msg( "sendPacket %u %u %u" , outgoing , incoming , bufSize ); return true; }