packet.h 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141
  1. /* Gearman server and library
  2. * Copyright (C) 2008 Brian Aker, Eric Day
  3. * All rights reserved.
  4. *
  5. * Use and distribution licensed under the BSD license. See
  6. * the COPYING file in the parent directory for full text.
  7. */
  8. /**
  9. * @file
  10. * @brief Packet Declarations
  11. */
  12. #pragma once
  13. #include <libgearman-server/struct/packet.h>
  14. #include <libgearman-1.0/protocol.h>
  15. #ifdef __cplusplus
  16. extern "C" {
  17. #endif
  18. /**
  19. * @addtogroup gearman_server_packet Packet Declarations
  20. * @ingroup gearman_server
  21. *
  22. * This is a low level interface for gearman server connections. This is used
  23. * internally by the server interface, so you probably want to look there first.
  24. *
  25. * @{
  26. */
  27. /**
  28. * Initialize a server packet structure.
  29. */
  30. GEARMAN_API
  31. gearman_server_packet_st *
  32. gearman_server_packet_create(gearman_server_thread_st *thread,
  33. bool from_thread);
  34. GEARMAN_LOCAL
  35. const char *gearmand_strcommand(gearmand_packet_st *packet);
  36. /**
  37. * Free a server connection structure.
  38. */
  39. GEARMAN_API
  40. void gearman_server_packet_free(gearman_server_packet_st *packet,
  41. gearman_server_thread_st *thread,
  42. bool from_thread);
  43. /**
  44. * Add a server packet structure to io queue for a connection.
  45. */
  46. GEARMAN_API
  47. gearmand_error_t gearman_server_io_packet_add(gearman_server_con_st *con,
  48. bool take_data,
  49. enum gearman_magic_t magic,
  50. gearman_command_t command,
  51. const void *arg, ...);
  52. /**
  53. * Remove the first server packet structure from io queue for a connection.
  54. */
  55. GEARMAN_API
  56. void gearman_server_io_packet_remove(gearman_server_con_st *con);
  57. /**
  58. * Add a server packet structure to proc queue for a connection.
  59. */
  60. GEARMAN_API
  61. void gearman_server_proc_packet_add(gearman_server_con_st *con,
  62. gearman_server_packet_st *packet);
  63. /**
  64. * Remove the first server packet structure from proc queue for a connection.
  65. */
  66. GEARMAN_API
  67. gearman_server_packet_st *
  68. gearman_server_proc_packet_remove(gearman_server_con_st *con);
  69. /**
  70. * Initialize a packet structure.
  71. *
  72. * @param[in] gearman Structure previously initialized with gearman_create() or
  73. * gearman_clone().
  74. * @param[in] packet Caller allocated structure, or NULL to allocate one.
  75. * @return On success, a pointer to the (possibly allocated) structure. On
  76. * failure this will be NULL.
  77. */
  78. GEARMAN_INTERNAL_API
  79. void gearmand_packet_init(gearmand_packet_st *packet, enum gearman_magic_t magic, gearman_command_t command);
  80. /**
  81. * Free a packet structure.
  82. *
  83. * @param[in] packet Structure previously initialized with
  84. * gearmand_packet_init() or gearmand_packet_creates().
  85. */
  86. GEARMAN_INTERNAL_API
  87. void gearmand_packet_free(gearmand_packet_st *packet);
  88. /**
  89. * Add an argument to a packet.
  90. */
  91. GEARMAN_INTERNAL_API
  92. gearmand_error_t gearmand_packet_create(gearmand_packet_st *packet,
  93. const void *arg, size_t arg_size);
  94. /**
  95. * Pack header.
  96. */
  97. GEARMAN_INTERNAL_API
  98. gearmand_error_t gearmand_packet_pack_header(gearmand_packet_st *packet);
  99. /**
  100. * Pack packet into output buffer.
  101. */
  102. GEARMAN_INTERNAL_API
  103. size_t gearmand_packet_pack(const gearmand_packet_st *packet,
  104. gearman_server_con_st *con,
  105. void *data, size_t data_size,
  106. gearmand_error_t *ret_ptr);
  107. /**
  108. * Unpack packet from input data.
  109. */
  110. GEARMAN_INTERNAL_API
  111. size_t gearmand_packet_unpack(gearmand_packet_st *packet,
  112. gearman_server_con_st *con,
  113. const void *data, size_t data_size,
  114. gearmand_error_t *ret_ptr);
  115. /** @} */
  116. #ifdef __cplusplus
  117. }
  118. #endif