/** Reads data from the intermediate buffer into the specified memory location. The function calls the virtual function UnderfLowL() to give concrete implementations the chance to refill the intermediate buffer, and satisfy the caller's requirements. This implementation overrides the one supplied by the base class MStreamBuf, and is called by, MStreamBuf::ReadL(TAny*,TInt). @param aPtr A pointer to the target memory location for the data read from the intermediate buffer. @param aMaxLength The maximum number of bytes to be read. @return The number of bytes read. This may be less than the amount requested. @see MStreamBuf::ReadL() @see MStreamBuf::DoReadL() */ EXPORT_C TInt TStreamBuf::DoReadL(TAny* aPtr,TInt aMaxLength) { __ASSERT_DEBUG(aMaxLength>=0,Panic(EStreamReadLengthNegative)); __ASSERT_DEBUG(aMaxLength>0,Panic(EStreamReadNoTransfer)); __ASSERT_DEBUG(Ptr(ERead)!=NULL||End(ERead)==NULL,Panic(EStreamCannotRead)); TInt left=aMaxLength; TInt avail=Avail(ERead); __ASSERT_DEBUG(avail>=0,User::Invariant()); if (avail==0) goto underflow; // do { __ASSERT_DEBUG(avail==Avail(ERead),Panic(EStreamUnderflowInBreach)); __ASSERT_DEBUG(left>0&&avail>0,User::Invariant()); { TInt len=Min(left,avail); TUint8* ptr=Ptr(ERead); aPtr=Mem::Copy(aPtr,ptr,len); SetPtr(ERead,ptr+len); left-=len; if (left==0) return aMaxLength; // that's it } // underflow: avail=UnderflowL(left); } while (avail>0); __ASSERT_DEBUG(avail==0&&Avail(ERead)==0,Panic(EStreamUnderflowInBreach)); return aMaxLength-left; }
/** Writes data from the specified memory location into the intermediate buffer. The function calls the virtual function OverfLowL() to give concrete implementations the chance to forward the intermediate buffer content to its destination. This implementation overrides the one supplied by the base class MStreamBuf, and is called by MStreamBuf::WriteL(const TAny*,TInt). @param aPtr A pointer to the source memory location for the data to be written to the intermediate buffer. @param aLength The number of bytes to be written. @return The number of bytes written. @see MStreamBuf::WriteL() @see MStreamBuf::DoWriteL() */ EXPORT_C void TStreamBuf::DoWriteL(const TAny* aPtr,TInt aLength) { __ASSERT_DEBUG(aLength>=0,Panic(EStreamWriteLengthNegative)); __ASSERT_DEBUG(aLength>0,Panic(EStreamWriteNoTransfer)); __ASSERT_DEBUG(Ptr(EWrite)!=NULL||End(EWrite)==NULL,Panic(EStreamCannotWrite)); TInt avail=Avail(EWrite); __ASSERT_DEBUG(avail>=0,User::Invariant()); if (avail==0) goto overflow; // for(;;) { __ASSERT_DEBUG(avail>0,Panic(EStreamOverflowInBreach)); __ASSERT_DEBUG(aLength>0,User::Invariant()); { TInt len=Min(aLength,avail); SetPtr(EWrite,Mem::Copy(Ptr(EWrite),aPtr,len)); aLength-=len; if (aLength==0) return; // done // aPtr=(TUint8*)aPtr+len; } // overflow: OverflowL(); avail=Avail(EWrite); }; }
/** Gets the number of bytes available in the read or write area within the intermediate buffer. @param anArea The area within the intermediate buffer for which the number of available bytes is to be fetched. This can be either the read area or the write area, as indicated by the ERead and EWrite bits. Only one of these can be set, otherwise the function raises a STORE-Stream 17 panic. @return The number of bytes available. */ EXPORT_C TInt TStreamBuf::Avail(TArea anArea) const { if (anArea==ERead) return Avail(ERead); // __ASSERT_ALWAYS(anArea==EWrite,Panic(EStreamAreaInvalid)); return Avail(EWrite); }
void TBufBuf::Consolidate() // // Empty buffer areas and, in truncate mode, cut off at the current write position. // { MovePos(ERead,-Avail(ERead)); MovePos(EWrite,-Avail(EWrite)); SetBuf(ERead|EWrite,NULL,NULL); if (iMode&ETruncate) { Buf().Delete(Pos(EWrite),Buf().Size()-Pos(EWrite)); iMode&=~ETruncate; } }
bool Fill(int iBeginRow,int iBeginCol) { int iEndRow,iEndCol,i,j; for(iEndRow=iBeginRow+1;iEndRow<=iHeight && cBoard[iEndRow][iBeginCol]==SHIP;iEndRow++); for(iEndCol=iBeginCol+1;iEndCol<=iWidth && cBoard[iBeginRow][iEndCol]==SHIP;iEndCol++); for(i=iBeginRow;i<iEndRow;i++)for(j=iBeginCol;j<iEndCol;j++) {if(cBoard[i][j]!=SHIP)return false;cBoard[i][j]=WATER;} for(i=iBeginRow-1;i<=iEndRow;i++) if((Avail(i,iBeginCol-1) && cBoard[i][iBeginCol-1]==SHIP) || (Avail(i,iEndCol) && cBoard[i][iEndCol]==SHIP)) return false; for(i=iBeginCol-1;i<=iEndCol;i++) if((Avail(iBeginRow-1,i) && cBoard[iBeginRow-1][i]==SHIP) || (Avail(iEndRow,i) && cBoard[iEndRow][i]==SHIP)) return false; return true; }
void CPocketController::Serialize( CAr & ar ) { if( ar.IsStoring() ) { for( int i = 0; i < MAX_POCKET; i++ ) { if( IsAvailable( i, FALSE ) ) { ar << (BYTE)1; m_apPocket[i]->Serialize( ar ); } else ar << (BYTE)0; } } else { Clear(); for( int i = 0; i < MAX_POCKET; i++ ) { BYTE bExists; ar >> bExists; if( !bExists ) continue; Avail( i ); m_apPocket[i]->Serialize( ar ); } } }
EXPORT_C TInt TDesBuf::UnderflowL(TInt) // // Check if there's any more to be read. // { Consolidate(); return Avail(ERead); }
virtual uval locked_isTransportFull() { _ASSERT_HELD(lock); uval avail = Avail(*pidx_ptr, *cidx_ptr, BlockDev::TransportNumEntries); tassertMsg(avail > 0 && avail < BlockDev::TransportNumEntries, "avail %ld\n", avail); //tassertWrn(avail != 1, "Transport for acks kernel disk obj full!\n"); return (avail == 1); }
CPocketController::CPocketController() { #ifdef __WORLDSERVER m_pMover = NULL; #endif // __WORLDSERVER memset( m_apPocket, 0, sizeof(m_apPocket) ); #ifndef __OPT_MEM_0811 Avail( 0 ); #endif // __OPT_MEM_0811 }
// // Default implementation filling the buffer before turning around to anOutput. // EXPORT_C TStreamTransfer TStreamBuf::DoWriteL(MStreamOutput& anOutput,TStreamTransfer aTransfer) { __ASSERT_DEBUG(aTransfer>0,Panic(EStreamWriteNoTransfer)); __ASSERT_DEBUG(Ptr(EWrite)!=NULL||End(EWrite)==NULL,Panic(EStreamCannotWrite)); __ASSERT_DEBUG(Avail(EWrite)>=0,User::Invariant()); TInt len=aTransfer[Avail(EWrite)]; if (len>0) { __DEBUG(TInt avail=Avail(EWrite)); // may be pulling from this streambuf TUint8* ptr=Ptr(EWrite); len=anOutput.PullL(ptr,len); __ASSERT_DEBUG(len>=0&&len<=aTransfer[avail]&&Ptr(EWrite)==ptr&&Avail(EWrite)>=avail,Panic(EStreamPullInBreach)); SetPtr(EWrite,ptr+len); aTransfer-=len; } if (aTransfer>0) aTransfer=anOutput.WriteToL(*this,aTransfer); return aTransfer; }
/** Reads data from the intermediate buffer and, if necessary, any remaining data from the stream to the specified target stream input object. It is called by ReadL(MStreamInput&,TStreamTransfer). The intermediate buffer is emptied first by calling the target stream input's PushL() function, which performs the read from intermediate buffer operation. Any remaining data is then read from the stream by calling the target stream object's ReadFromL() function, which performs the read from stream operation. This implementation is called for streams that have buffering capabilities and are derived from this class. @param anInput The target stream input object. @param aTransfer A stream transfer object defining the amount of data available to be written. @return The amount of data that was not consumed. @see MStreamInput::ReadFromL() @see MStreamInput::PushL() */ EXPORT_C TStreamTransfer TStreamBuf::DoReadL(MStreamInput& anInput,TStreamTransfer aTransfer) { __ASSERT_DEBUG(aTransfer>0,Panic(EStreamReadNoTransfer)); __ASSERT_DEBUG(Ptr(ERead)!=NULL||End(ERead)==NULL,Panic(EStreamCannotRead)); __ASSERT_DEBUG(Avail(ERead)>=0,User::Invariant()); TInt len=aTransfer[Avail(ERead)]; if (len>0) { __DEBUG(TInt avail=Avail(ERead)); // may be pushing into this streambuf TUint8* ptr=Ptr(ERead); len=anInput.PushL(ptr,len); __ASSERT_DEBUG(len>=0&&len<=aTransfer[avail]&&Ptr(ERead)==ptr&&Avail(ERead)>=avail,Panic(EStreamPushInBreach)); SetPtr(ERead,ptr+len); aTransfer-=len; } if (aTransfer>0) aTransfer=anInput.ReadFromL(*this,aTransfer); return aTransfer; }
void CPocketController::Copy( CPocketController & rPocketController ) { Clear(); for( int i = 0; i < MAX_POCKET; i++ ) { if( rPocketController.IsAvailable( i, FALSE ) ) { Avail( i ); m_apPocket[i]->Copy( *rPocketController.m_apPocket[i] ); } } }
void CPocketController::SetAttribute( int nAttribute, int nPocket, int nData ) { switch( nAttribute ) { case expired: { if( IsAvailable( nPocket, FALSE ) ) m_apPocket[nPocket]->SetExpired( (BOOL)nData ); break; } case avail: { Avail( nPocket, (time_t)nData ); break; } default: break; } #ifdef __WORLDSERVER ( (CUser*)m_pMover )->AddPocketAttribute( nAttribute, nPocket, nData ); #endif // __WORLDSERVER }
inline bool Empty() const { return !Avail(); }
/* virtual */ SysStatus SharedBufferProducer::locked_put(uval *request, uval highPriority, uval shouldBlock) { _ASSERT_HELD(lock); tassertMsg(pidx_ptr != NULL && pidx_ptr > baseAddr, "?"); tassertMsg(cidx_ptr != NULL && cidx_ptr == pidx_ptr + 1, "?"); tassertMsg(*pidx_ptr < numEntries, "?"); tassertMsg(*cidx_ptr < numEntries, "?"); SysStatus rc; retry: rc = 0; while (locked_isTransportFull()) { /* we already have too many ongoing requests (maximum our * data structure holds is numEntries-1; it may be that some of those * outstanding have already been consumed out of the buffer, but * still we don't want to have too many outstanding requests * because our consumer may not be able to handle them. */ if (shouldBlock) { rc = locked_block(highPriority); tassertMsg(_SUCCESS(rc), "?"); } else { return _SERROR(2859, 0, EBUSY); } } outstanding++; uval *ptr = (uval*) ((*pidx_ptr)*entryUvals + baseAddr) ; memcpy(ptr, request, entryUvals * sizeof(uval)); uval old_pidx = *pidx_ptr; *pidx_ptr = (*pidx_ptr + 1) % numEntries; /* maximum available is numEntries - 1; we're detecting going from * empty to non empty */ if (Avail(*pidx_ptr, *cidx_ptr, numEntries) == numEntries - 2) { //err_printf("KICK"); rc = kickConsumer(); if (_FAILURE(rc)) { if (_SGENCD(rc) == EBUSY) { /* FIXME: for now we assume that if we can't send the * async call, we have ongoing operations */ tassertWrn(0, "kickConsumer returned EBUSY\n"); outstanding--; // do not count current one passertMsg(outstanding >= 0, "outstanding %ld\n", outstanding); *pidx_ptr = old_pidx; // take the entry if (shouldBlock) { // let's sleep and try again when progress has been made rc = locked_block(highPriority); goto retry; } else { return _SERROR(2860, 0, EBUSY); } } else if (_SGENCD(rc) == EINVAL) { // consumer process has gone away outstanding--; // do not count current one passertMsg(outstanding != 0, "basic assumption broken\n"); *pidx_ptr = old_pidx; // take the entry return _SERROR(2932, 0, EINVAL); } passertMsg(_SUCCESS(rc), "look at this error rc 0x%lx\n", rc); } } else { //err_printf("#%ld(%ld,%ld)#\n", outstanding, *pidx_ptr, *cidx_ptr); } return rc; }
// --------------------------------------------------------- // RFavouritesBuf::UnderflowL() // --------------------------------------------------------- // TInt RFavouritesBuf::UnderflowL( TInt /*aMaxLength*/ ) { __ASSERT_DEBUG( Avail( ERead ) == 0, \ FavouritesPanic( EFavouritesInternal ) ); return IpcReadL(); }
// --------------------------------------------------------- // RFavouritesBuf::OverflowL() // --------------------------------------------------------- // void RFavouritesBuf::OverflowL() { __ASSERT_DEBUG( Avail( EWrite ) == 0, \ FavouritesPanic( EFavouritesInternal ) ); IpcWriteL(); }
uint8_t SerialHandler::available(void){ return Avail(); }