buf.h 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. /** @file buf.h
  2. * @brief Public interface for dynamic buffer class.
  3. */
  4. #ifndef _faux_buf_h
  5. #define _faux_buf_h
  6. #include <faux/faux.h>
  7. #include <faux/sched.h>
  8. #define FAUX_BUF_UNLIMITED 0
  9. typedef struct faux_buf_s faux_buf_t;
  10. C_DECL_BEGIN
  11. faux_buf_t *faux_buf_new(size_t chunk_size);
  12. void faux_buf_free(faux_buf_t *buf);
  13. ssize_t faux_buf_len(const faux_buf_t *buf);
  14. ssize_t faux_buf_limit(const faux_buf_t *buf);
  15. bool_t faux_buf_set_limit(faux_buf_t *buf, size_t limit);
  16. bool_t faux_buf_will_be_overflow(const faux_buf_t *buf, size_t add_len);
  17. size_t faux_buf_is_wlocked(const faux_buf_t *buf);
  18. size_t faux_buf_is_rlocked(const faux_buf_t *buf);
  19. ssize_t faux_buf_write(faux_buf_t *buf, const void *data, size_t len);
  20. ssize_t faux_buf_read(faux_buf_t *buf, void *data, size_t len);
  21. ssize_t faux_buf_dread_lock(faux_buf_t *buf, size_t len,
  22. struct iovec **iov, size_t *iov_num);
  23. ssize_t faux_buf_dread_unlock(faux_buf_t *buf, size_t really_readed,
  24. struct iovec *iov);
  25. ssize_t faux_buf_dwrite_lock(faux_buf_t *buf, size_t len,
  26. struct iovec **iov_out, size_t *iov_num_out);
  27. ssize_t faux_buf_dwrite_unlock(faux_buf_t *buf, size_t really_written,
  28. struct iovec *iov);
  29. ssize_t faux_buf_dwrite_lock_easy(faux_buf_t *buf, void **data);
  30. ssize_t faux_buf_dwrite_unlock_easy(faux_buf_t *buf, size_t really_written);
  31. ssize_t faux_buf_dread_lock_easy(faux_buf_t *buf, void **data);
  32. ssize_t faux_buf_dread_unlock_easy(faux_buf_t *buf, size_t really_readed);
  33. C_DECL_END
  34. #endif // _faux_buf_h