libfuncs is collection of code (list, queue, circular buffer, io, logging, etc.). https://georgi.unixsol.org/programs/libfuncs/
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

cbuf.h 950B

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. /*
  2. * Circular buffer header file
  3. * Copyright (C) 2010 Unix Solutions Ltd.
  4. *
  5. * Released under MIT license.
  6. * See LICENSE-MIT.txt for license terms.
  7. */
  8. #ifndef CBUF_H
  9. #define CBUF_H
  10. #include <netdb.h>
  11. // Circular buffer
  12. typedef struct {
  13. pthread_mutex_t lock;
  14. char *name;
  15. int size; /* Buffer size, must be (bufsize % 1316) == 0 */
  16. int pos; /* Up to where the buffer is filled */
  17. int writepos; /* Up to where the buffer is get */
  18. void *buffer; /* The buffer data */
  19. uint64_t input;
  20. uint64_t output;
  21. int pos_wrapped;
  22. int debug_get;
  23. } CBUF;
  24. CBUF *cbuf_init(int buffer_size, char *name);
  25. void cbuf_free(CBUF **buffer);
  26. int cbuf_fill(CBUF *b, uint8_t *data, int datasize);
  27. void *cbuf_get(CBUF *b, int size, int *ret_datasize);
  28. void *cbuf_peek(CBUF *b, int size, int *ret_datasize);
  29. void cbuf_copy(CBUF *src, CBUF *dest);
  30. int cbuf_data_size(CBUF *b);
  31. void cbuf_poison(CBUF *b, char poison_byte);
  32. void cbuf_dump(CBUF *b);
  33. #endif