message.h 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. /* This file is part of libepistle.
  2. *
  3. * libepistle is free software: you can redistribute it and/or modify
  4. * it under the terms of the GNU Lesser General Public License as published by
  5. * the Free Software Foundation, either version 3 of the License, or
  6. * (at your option) any later version.
  7. *
  8. * libepistle is distributed in the hope that it will be useful,
  9. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  11. * GNU Lesser General Public License for more details.
  12. *
  13. * You should have received a copy of the GNU Lesser General Public License
  14. * along with libepistle. If not, see <http://www.gnu.org/licenses/>.
  15. */
  16. #ifndef EPISTLE_MESSAGE_H
  17. #define EPISTLE_MESSAGE_H
  18. #include <primo/err.h>
  19. #include <stdint.h>
  20. /* Note on symmetry of sending and receiving:
  21. A message that has been received can be send, but before you can receive
  22. on a Msg structure that has been sent you need to call message_recv_init()
  23. (and you probably want to dispose as well). */
  24. typedef struct {
  25. uint32_t len;
  26. uint32_t len_tnsfd;
  27. unsigned char *buf;
  28. uint32_t buf_tnsfd;
  29. unsigned buf_freeable : 1;
  30. } Msg;
  31. int
  32. msg_copy(Msg *des, const Msg *src, Err *err);
  33. int
  34. msg_extend(Msg *msg, uint32_t amt, Err *err);
  35. void
  36. msg_send_init(Msg *msg, uint32_t len, void *buf, int buf_freeable);
  37. int
  38. msg_send(int fd, Msg *msg, int wait, Err *err);
  39. void
  40. msg_recv_init(Msg *msg);
  41. int
  42. msg_recv(int fd, Msg *msg, uint32_t max_len, int wait, Err *err);
  43. void
  44. msg_dispose(Msg *msg);
  45. int
  46. msg_tnsfd(Msg *msg);
  47. void
  48. msg_reuse(Msg *msg);
  49. #endif