** * @briefReturn number of bytes in the ring buffer that can be retrieved in ascending linear order from tail * @paramRingBuff: Pointer to ring buffer * @returnNumber of bytes in linear order */ int RingBuffer_GetCountLinear(RINGBUFF_T *RingBuff) { return MIN(RingBuffer_GetCount(RingBuff),RingBuff->count - RB_INDT(RingBuff)); } /** * @briefReturn pointer to tail * @paramRingBuff: Pointer to ring buffer * @returnPointer to tail */ STATIC INLINE void* RingBuffer_GetTail(RINGBUFF_T *RingBuff) { return RingBuff->data+RB_INDT(RingBuff); } /** * @briefMove tail pointer by n bytes (deletes n oldest bytes) * @paramRingBuff: Pointer to ring buffer * @paramn: number of bytes to be deleted * @returnNumber of bytes deleted */ int RingBuffer_MoveTail(RINGBUFF_T *RingBuff, int n) { if (RingBuffer_GetCount(RingBuff) < n) n=RingBuffer_GetCount(RingBuff); RingBuff->tail+=n; return n; } |
// if the buffer is not empty, then stuff as much as possible into the LWIP buffers again if (!RingBuffer_IsEmpty(&out.rb)) { // get number of bytes that can be copied/accessed in ascending order n=MIN(tcp_sndbuf(lwip_dbg.accepted), RingBuffer_GetCountLinear(&out.rb)); // copy data directly from ringbuffer memory to LWIP memory tcp_write(lwip_dbg.accepted, RingBuffer_GetTail(&out.rb), n, TCP_WRITE_FLAG_COPY); // free ringbuffer memory RingBuffer_MoveTail(&out.rb, n); } |