Mirror of :pserver:cvs@cvs.fefe.de:/cvs libowfat https://www.fefe.de/libowfat/
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.
 
 
 
 

49 lines
1.5 KiB

  1. /* this header file comes from libowfat, http://www.fefe.de/libowfat/ */
  2. #ifndef IOB_H
  3. #define IOB_H
  4. /* These functions can be used to create a queue of small (or large)
  5. * buffers and parts of files to be sent out over a socket. It is meant
  6. * for writing HTTP servers or the like. */
  7. /* This API works with non-blocking I/O. Simply call iob_send until it
  8. * returns 0 (or -1). The implementation uses sendfile for zero-copy
  9. * TCP and it will employ writev (or the built-in sendfile writev on
  10. * BSD) to make sure the output fragments are coalesced into as few TCP
  11. * frames as possible. On Linux it will also use the TCP_CORK socket
  12. * option. */
  13. #include "libowfat/io.h"
  14. #include "libowfat/array.h"
  15. #ifdef __cplusplus
  16. extern "C" {
  17. #endif
  18. typedef struct io_batch {
  19. array b;
  20. uint64 bytesleft;
  21. long next,bufs,files;
  22. } io_batch;
  23. io_batch* iob_new(int hint_entries);
  24. int iob_addbuf(io_batch* b,const void* buf,uint64 n);
  25. int iob_addbuf_free(io_batch* b,const void* buf,uint64 n);
  26. int iob_addbuf_munmap(io_batch* b,const void* buf,uint64 n);
  27. int iob_adds(io_batch* b,const char* s);
  28. int iob_adds_free(io_batch* b,const char* s);
  29. int iob_addfile(io_batch* b,int64 fd,uint64 off,uint64 n);
  30. int iob_addfile_close(io_batch* b,int64 fd,uint64 off,uint64 n);
  31. int64 iob_send(int64 s,io_batch* b);
  32. int64 iob_write(int64 s,io_batch* b,io_write_callback cb);
  33. void iob_reset(io_batch* b);
  34. void iob_free(io_batch* b);
  35. void iob_prefetch(io_batch* b,uint64 bytes);
  36. uint64 iob_bytesleft(const io_batch* b);
  37. #ifdef __cplusplus
  38. }
  39. #endif
  40. #endif