Ignore:
Timestamp:
01/02/13 13:58:25 (11 years ago)
Author:
István Váradi <ivaradi@…>
Branch:
default
Phase:
public
Message:

Implemented the data stream

File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/xplcommon/BlockingStream.cc

    r30 r31  
    4646//------------------------------------------------------------------------------
    4747
    48 bool BlockingStream::isInterrupted()
     48inline bool BlockingStream::checkInterrupted()
    4949{
    50     if (failed()) return false;
    51 
    5250    if (!interrupted) {
    5351        interrupted = event.check();
     
    8381//------------------------------------------------------------------------------
    8482
     83bool BlockingStream::skip(size_t length)
     84{
     85    ReadingBuffer& readingBuffer = stream.getReadingBuffer();
     86    while (length>0) {
     87        size_t toSkip = min(length, readingBuffer.getLength() - readingOffset);
     88        readingOffset += toSkip;
     89        length -= toSkip;
     90
     91        if (length!=0) {
     92            if (!fill()) return false;
     93        }
     94    }
     95
     96    return true;
     97}
     98
     99//------------------------------------------------------------------------------
     100
    85101bool BlockingStream::write(const void* src, size_t length)
    86102{
     
    105121{
    106122    WritingBuffer& writingBuffer = stream.getWritingBuffer();
    107     while (!failed()) {
    108         if (isInterrupted()) return false;
     123    while (*this) {
     124        if (checkInterrupted()) return false;
    109125
    110126        if (writingBuffer.write()) {
     
    112128        } else if (writingBuffer.failed()) {
    113129            setErrorCode(writingBuffer.getErrorCode());
    114             return false;
    115130        } else {
    116131            Waiter* waiter = stream.getWaiter();
     
    132147    readingBuffer.reset();
    133148    readingOffset = 0;
    134     while (true) {
    135         if (isInterrupted()) return false;
     149    while (*this) {
     150        if (checkInterrupted()) return false;
    136151
    137152        if (readingBuffer.read()) {
    138             return !readingBuffer.isEmpty();
     153            eof = readingBuffer.isEmpty();
     154            return !eof;
    139155        } else if (readingBuffer.failed()) {
    140156            setErrorCode(readingBuffer.getErrorCode());
    141             return false;
    142157        } else {
    143158            Waiter* waiter = stream.getWaiter();
     
    149164        }
    150165    }
     166    return false;
    151167}
    152168
Note: See TracChangeset for help on using the changeset viewer.