xant / libhl

Simple and fast C library implementing a thread-safe API to manage hash-tables, linked lists, lock-free ring buffers and queues
GNU Lesser General Public License v3.0
420 stars 117 forks source link

Is there any document to introduce the APIs? #25

Closed tianchao-haohan closed 5 years ago

tianchao-haohan commented 6 years ago

About how to use the opened APIs and the meaning of the return value.

tianchao-haohan commented 6 years ago

For example , if the mode of rqueue is RQUEUE_MODE_OVERWRITE, how do I know the ring is overwritten from the return value? And whether the operation is written successfully.

xant commented 5 years ago

The documentation is what you have in the headers. The return value in rbuf_write() indicates how many bytes have been written and let you detect if the ringbuffer is full when RBUF_MODE_BLOCKING. In case of RBUF_MODE_OVERWRITE you don't have any indication that the overwrite occurred but the write will always succeed for the whole input buffer. Obviously you can look at the value returned rbuf_available() before writing so you know if your write is going to overflow the ringbuffer (and cause overwrites) or not.

Feel free to open a pull request if you have any improvement to the headerdoc