deps/libcows/buffers.c
size_t cbuf_chain_fill_iov(cbuf_chain *chain, struct iovec *vec, size_t veclen, size_t *remaining) {
    size_t n = 0;

    if(remaining) *remaining = 0;

    if(!chain)
        return n;

    cbuf *cb, *tmp_cb;
    STAILQ_FOREACH_SAFE(cb, &chain->head, next, tmp_cb) {
        size_t avail = cb->write_offset - cb->read_offset;
        if(avail) {
            if(veclen) {
                vec[0].iov_base = cb->read_offset;
                vec[0].iov_len = avail;
                vec++;
                veclen--;
                n++;
                chain->data_size -= avail;
                STAILQ_REMOVE_HEAD(&chain->head, next);
                STAILQ_INSERT_HEAD(&chain->zombies, cb, next);
            } else {
                if(remaining) *remaining += avail;
                else break;
            }
        } else {
            STAILQ_REMOVE_HEAD(&chain->head, next);
            STAILQ_INSERT_HEAD(&chain->zombies, cb, next);
        }
    }

    return n;
}
/*
 * Fill the I/O vector with the next pieces of from the chain.
 * This function can be invoked over and over again, yielding new data.
 * RETURN VALUE:
 *   0: No more data in the chain or no space in the given iov.
 *   n: Number of iov slots filled up with pointers to data.
 */
Fill the I/O vector with the next pieces of from the chain.
This function can be invoked over and over again, yielding new data.
RETURN VALUE:
0: No more data in the chain or no space in the given iov.
n: Number of iov slots filled up with pointers to data.
Fill the I / O vector with the next pieces of from the chain . This function can be invoked over and over again yielding new data . RETURN VALUE : 0 : No more data in the chain or no space in the given iov . n : Number of iov slots filled up with pointers to data .
size_t cbuf_chain_fill_iov(cbuf_chain *chain, struct iovec *vec, size_t veclen, size_t *remaining) {
    size_t n = 0;
    if(remaining) *remaining = 0;
    if(!chain)
        return n;
    cbuf *cb, *tmp_cb;
    STAILQ_FOREACH_SAFE(cb, &chain->head, next, tmp_cb) {
        size_t avail = cb->write_offset - cb->read_offset;
        if(avail) {
            if(veclen) {
                vec[0].iov_base = cb->read_offset;
                vec[0].iov_len = avail;
                vec++;
                veclen--;
                n++;
                chain->data_size -= avail;
                STAILQ_REMOVE_HEAD(&chain->head, next);
                STAILQ_INSERT_HEAD(&chain->zombies, cb, next);
            } else {
                if(remaining) *remaining += avail;
                else break;
            }
        } else {
            STAILQ_REMOVE_HEAD(&chain->head, next);
            STAILQ_INSERT_HEAD(&chain->zombies, cb, next);
        }
    }
    return n;
}
size_t cbuf_chain_fill_iov ( cbuf_chain * chain , struct iovec * vec , size_t veclen , size_t * remaining ) { size_t n = 0 ; if ( remaining ) * remaining = 0 ; if ( ! chain ) return n ; cbuf * cb , * tmp_cb ; STAILQ_FOREACH_SAFE ( cb , & chain -> head , next , tmp_cb ) { size_t avail = cb -> write_offset - cb -> read_offset ; if ( avail ) { if ( veclen ) { vec [ 0 ] . iov_base = cb -> read_offset ; vec [ 0 ] . iov_len = avail ; vec ++ ; veclen -- ; n ++ ; chain -> data_size -= avail ; STAILQ_REMOVE_HEAD ( & chain -> head , next ) ; STAILQ_INSERT_HEAD ( & chain -> zombies , cb , next ) ; } else { if ( remaining ) * remaining += avail ; else break ; } } else { STAILQ_REMOVE_HEAD ( & chain -> head , next ) ; STAILQ_INSERT_HEAD ( & chain -> zombies , cb , next ) ; } } return n ; }
Fill the I/O vector with the next pieces of from the chain.
Fill the I / O vector with the next pieces of from the chain .