packet.h 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154
  1. /* vim:expandtab:shiftwidth=2:tabstop=2:smarttab:
  2. *
  3. * Gearmand client and server library.
  4. *
  5. * Copyright (C) 2011-2012 Data Differential, http://datadifferential.com/
  6. * Copyright (C) 2008 Brian Aker, Eric Day
  7. * All rights reserved.
  8. *
  9. * Redistribution and use in source and binary forms, with or without
  10. * modification, are permitted provided that the following conditions are
  11. * met:
  12. *
  13. * * Redistributions of source code must retain the above copyright
  14. * notice, this list of conditions and the following disclaimer.
  15. *
  16. * * Redistributions in binary form must reproduce the above
  17. * copyright notice, this list of conditions and the following disclaimer
  18. * in the documentation and/or other materials provided with the
  19. * distribution.
  20. *
  21. * * The names of its contributors may not be used to endorse or
  22. * promote products derived from this software without specific prior
  23. * written permission.
  24. *
  25. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
  26. * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
  27. * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
  28. * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
  29. * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
  30. * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
  31. * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
  32. * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
  33. * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  34. * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
  35. * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  36. *
  37. */
  38. /**
  39. * @file
  40. * @brief Packet Declarations
  41. */
  42. #pragma once
  43. #include <libgearman-server/struct/packet.h>
  44. #include <libgearman-1.0/protocol.h>
  45. #ifdef __cplusplus
  46. extern "C" {
  47. #endif
  48. /**
  49. * @addtogroup gearman_server_packet Packet Declarations
  50. * @ingroup gearman_server
  51. *
  52. * This is a low level interface for gearman server connections. This is used
  53. * internally by the server interface, so you probably want to look there first.
  54. *
  55. * @{
  56. */
  57. /**
  58. * Initialize a server packet structure.
  59. */
  60. GEARMAN_API
  61. gearman_server_packet_st *
  62. gearman_server_packet_create(gearman_server_thread_st *thread,
  63. bool from_thread);
  64. const char *gearmand_strcommand(gearmand_packet_st *packet);
  65. /**
  66. * Free a server connection structure.
  67. */
  68. GEARMAN_API
  69. void gearman_server_packet_free(gearman_server_packet_st *packet,
  70. gearman_server_thread_st *thread,
  71. bool from_thread);
  72. /**
  73. * Add a server packet structure to io queue for a connection.
  74. */
  75. GEARMAN_API
  76. gearmand_error_t gearman_server_io_packet_add(gearman_server_con_st *con,
  77. bool take_data,
  78. enum gearman_magic_t magic,
  79. gearman_command_t command,
  80. const void *arg, ...);
  81. /**
  82. * Remove the first server packet structure from io queue for a connection.
  83. */
  84. GEARMAN_API
  85. void gearman_server_io_packet_remove(gearman_server_con_st *con);
  86. /**
  87. * Add a server packet structure to proc queue for a connection.
  88. */
  89. GEARMAN_API
  90. void gearman_server_proc_packet_add(gearman_server_con_st *con,
  91. gearman_server_packet_st *packet);
  92. /**
  93. * Remove the first server packet structure from proc queue for a connection.
  94. */
  95. GEARMAN_API
  96. gearman_server_packet_st *
  97. gearman_server_proc_packet_remove(gearman_server_con_st *con);
  98. /**
  99. * Initialize a packet structure.
  100. *
  101. * @param[in] gearman Structure previously initialized with gearman_create() or
  102. * gearman_clone().
  103. * @param[in] packet Caller allocated structure, or NULL to allocate one.
  104. * @return On success, a pointer to the (possibly allocated) structure. On
  105. * failure this will be NULL.
  106. */
  107. GEARMAN_INTERNAL_API
  108. void gearmand_packet_init(gearmand_packet_st *packet, enum gearman_magic_t magic, gearman_command_t command);
  109. /**
  110. * Free a packet structure.
  111. *
  112. * @param[in] packet Structure previously initialized with
  113. * gearmand_packet_init() or gearmand_packet_creates().
  114. */
  115. GEARMAN_INTERNAL_API
  116. void gearmand_packet_free(gearmand_packet_st *packet);
  117. /**
  118. * Add an argument to a packet.
  119. */
  120. GEARMAN_INTERNAL_API
  121. gearmand_error_t gearmand_packet_create(gearmand_packet_st *packet,
  122. const void *arg, size_t arg_size);
  123. /**
  124. * Pack header.
  125. */
  126. GEARMAN_INTERNAL_API
  127. gearmand_error_t gearmand_packet_pack_header(gearmand_packet_st *packet);
  128. void destroy_gearman_server_packet_st(gearman_server_packet_st *packet);
  129. /** @} */
  130. #ifdef __cplusplus
  131. }
  132. #endif