net.h 3.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. /** @file net.h
  2. * @brief Public interface for faux net functions.
  3. */
  4. #ifndef _faux_net_h
  5. #define _faux_net_h
  6. #include <faux/faux.h>
  7. typedef struct faux_net_s faux_net_t;
  8. typedef struct faux_pollfd_s faux_pollfd_t;
  9. typedef int faux_pollfd_iterator_t;
  10. C_DECL_BEGIN
  11. // Network base I/O functions
  12. ssize_t faux_send(int fd, const void *buf, size_t n,
  13. const struct timespec *timeout, const sigset_t *sigmask);
  14. ssize_t faux_send_block(int fd, const void *buf, size_t n,
  15. const struct timespec *timeout, const sigset_t *sigmask,
  16. int (*isbreak_func)(void));
  17. ssize_t faux_sendv(int fd, const struct iovec *iov, int iovcnt,
  18. const struct timespec *timeout, const sigset_t *sigmask);
  19. ssize_t faux_sendv_block(int fd, const struct iovec *iov, int iovcnt,
  20. const struct timespec *timeout, const sigset_t *sigmask,
  21. int (*isbreak_func)(void));
  22. ssize_t faux_recv(int fd, void *buf, size_t n,
  23. const struct timespec *timeout, const sigset_t *sigmask);
  24. ssize_t faux_recv_block(int fd, void *buf, size_t n,
  25. const struct timespec *timeout, const sigset_t *sigmask,
  26. int (*isbreak_func)(void));
  27. ssize_t faux_recvv(int fd, struct iovec *iov, int iovcnt,
  28. const struct timespec *timeout, const sigset_t *sigmask);
  29. ssize_t faux_recvv_block(int fd, struct iovec *iov, int iovcnt,
  30. const struct timespec *timeout, const sigset_t *sigmask,
  31. int (*isbreak_func)(void));
  32. // Network class
  33. faux_net_t *faux_net_new(void);
  34. void faux_net_free(faux_net_t *faux_net);
  35. void faux_net_set_fd(faux_net_t *faux_net, int fd);
  36. int faux_net_get_fd(faux_net_t *faux_net);
  37. void faux_net_set_send_timeout(faux_net_t *faux_net, struct timespec *send_timeout);
  38. void faux_net_set_recv_timeout(faux_net_t *faux_net, struct timespec *recv_timeout);
  39. void faux_net_set_timeout(faux_net_t *faux_net, struct timespec *timeout);
  40. void faux_net_set_isbreak_func(faux_net_t *faux_net, int (*isbreak_func)(void));
  41. void faux_net_sigmask_empty(faux_net_t *faux_net);
  42. void faux_net_sigmask_fill(faux_net_t *faux_net);
  43. void faux_net_sigmask_add(faux_net_t *faux_net, int signum);
  44. void faux_net_sigmask_del(faux_net_t *faux_net, int signum);
  45. ssize_t faux_net_send(faux_net_t *faux_net, const void *buf, size_t n);
  46. ssize_t faux_net_sendv(faux_net_t *faux_net,
  47. const struct iovec *iov, int iovcnt);
  48. ssize_t faux_net_recv(faux_net_t *faux_net, void *buf, size_t n);
  49. ssize_t faux_net_recvv(faux_net_t *faux_net, struct iovec *iov, int iovcnt);
  50. // Pollfd class
  51. faux_pollfd_t *faux_pollfd_new(void);
  52. void faux_pollfd_free(faux_pollfd_t *faux_pollfd);
  53. struct pollfd *faux_pollfd_vector(faux_pollfd_t *faux_pollfd);
  54. size_t faux_pollfd_len(faux_pollfd_t *faux_pollfd);
  55. struct pollfd *faux_pollfd_item(faux_pollfd_t *faux_pollfd, unsigned int index);
  56. struct pollfd *faux_pollfd_find(faux_pollfd_t *faux_pollfd, int fd);
  57. struct pollfd *faux_pollfd_add(faux_pollfd_t *faux_pollfd, int fd, short events);
  58. int faux_pollfd_del_by_fd(faux_pollfd_t *faux_pollfd, int fd);
  59. int faux_pollfd_del_by_index(faux_pollfd_t *faux_pollfd, unsigned int index);
  60. void faux_pollfd_init_iterator(faux_pollfd_t *faux_pollfd, faux_pollfd_iterator_t *iterator);
  61. struct pollfd *faux_pollfd_each(faux_pollfd_t *faux_pollfd, faux_pollfd_iterator_t *iterator);
  62. struct pollfd *faux_pollfd_each_active(faux_pollfd_t *faux_pollfd, faux_pollfd_iterator_t *iterator);
  63. C_DECL_END
  64. #endif