ErrorCode BufferProcessor::readDelimeter(char *output, unsigned int outputSize, unsigned int *outputLen, char delimeter) { while(1) { if (isTerminated()) return ErrorCode::TERMINATED; if (findCharacter(mReadBuffer, mReadBufferLen, outputLen, 0x0A)) { // There is newline in the ReadBuffer, // we will copy the part till newline to line buffer // and then shift the remaining buffer (*outputLen)++; return extractBuffer(output, outputSize, *outputLen); } else { if (bufferFull()) { // line is too long return ErrorCode::SEGMENT_TOO_LONG; } ErrorCode rval = fillBuffer(); assert(rval != ErrorCode::FAILURE); if (rval != ErrorCode::SUCCESS) return rval; continue; } } }
void SimulatorIMP::fillUpdateBuffer() { while (!bufferFull()) { for(auto& tp : tpacks) //round robin postingsInUpdateBuffer += tp.addUBPostings(); if(finished()) break; } }
static void bufferWrite( owl_buffer *buffer, const char *data, owl_offset num_bytes ) { //************************************************************************************* owl_offset bytes_remaining; owl_offset chunk_size; assert( buffer->location <= buffer->size ); bytes_remaining = num_bytes; while( bytes_remaining ) { if( bufferFull( buffer ) ) { bufferCollapse( buffer ); } chunk_size = bufferBinBytesLeft( buffer ); if( bytes_remaining < chunk_size ) { chunk_size = bytes_remaining; } bufferFill( buffer, data, chunk_size ); bytes_remaining -= chunk_size; if( data != NULL ) { data += chunk_size; } buffer->location += chunk_size; } }
//*************************************************************************** void Kwave::RecordThread::run() { int result = 0; bool interrupted = false; unsigned int offset = 0; // read data until we receive a close signal while (!shouldStop() && !interrupted) { // dequeue a buffer from the "empty" queue if (m_empty_queue.isEmpty()) { // we had a "buffer overflow" qWarning("RecordThread::run() -> NO EMPTY BUFFER FOUND !!!"); result = -ENOBUFS; break; } QByteArray buffer = m_empty_queue.dequeue(); int len = buffer.size(); Q_ASSERT(buffer.size()); if (!len) { result = -ENOBUFS; break; } // read into the current buffer offset = 0; while (len && !interrupted && !shouldStop()) { // read raw data from the record device result = (m_device) ? m_device->read(buffer, offset) : -EBADF; if ((result < 0) && (result != -EAGAIN)) qWarning("RecordThread: read result = %d (%s)", result, strerror(-result)); if (result == -EAGAIN) { continue; } else if (result == -EBADF) { // file open has failed interrupted = true; break; } else if (result == -EINTR) { // thread was interrupted, received signal? interrupted = true; break; } else if (result < 1) { // something went wrong !? interrupted = true; qWarning("RecordThread::run(): read returned %d", result); break; } else { offset += result; len = buffer.size() - offset; Q_ASSERT(len >= 0); if (len < 0) len = 0; } } // return buffer into the empty queue and abort on errors // do not use it if (interrupted && (result < 0)) { m_empty_queue.enqueue(buffer); break; } // inform the application that there is something to dequeue m_full_queue.enqueue(buffer); emit bufferFull(); } // do not evaluate the result of the last operation if there // was the external request to stop if (shouldStop() || (interrupted && (result > 0))) result = 0; if (result) emit stopped(result); }
// would be called by parser thread bool FLVParser::parseNextChunk() { bool indexOnly = bufferFull(); // won't lock, but our caller locked... return parseNextTag(indexOnly); }