Should tx_size be set to the size of a single chunk of data, or all the data in the buffer? Otherwise, cbuffer_pop_front(rx2) would return the 20 or so chunks you pushed back in lines 22-26.