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

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

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

Definition at line 46 of file bytebuffer.cpp.

References space().

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

    flushed = closed = false;
    while (space() < len) {
        if (blocking) {
            pthread_cond_wait(&not_full, &mutex);
            if (flushed || released) len = 0;
        }
        else
            len = space();
    }

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

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

    writePos = (writePos+len) % length;

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


Generated by  Doxygen 1.6.0   Back to index