Logo Search packages:      
Sourcecode: akode version File versions  Download package

int aKode::ByteBuffer::read ( char *  buf,
unsigned int  len,
bool  blocking = false 
)

Read len bytes from the buffer into buf. If blocking is set to true, read will block until len bytes have been read or release() is called. Returns the number of bytes read.

Definition at line 77 of file bytebuffer.cpp.

References content().

{
    pthread_mutex_lock(&mutex);
    if (released) len = 0;
    if (closed) blocking = false;

    while (content() < len) {
        if (blocking) {
            pthread_cond_wait(&not_empty, &mutex);
            if (released)
                len = 0;
            else if (closed)
                len = content();
        }
        else
            len = content();
    }

    unsigned int base = len, rem = 0;
    if (readPos+len > length) {
        base = length-readPos;
        rem = len-base;
    }

    memcpy(buf, buffer+readPos, base);
    memcpy(buf+base, buffer, rem);

    readPos = (readPos+len) % length;

    pthread_cond_signal(&not_full);
    pthread_mutex_unlock(&mutex);
    return len;
}


Generated by  Doxygen 1.6.0   Back to index