connection.h 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209
  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 Connection Declarations
  41. */
  42. #pragma once
  43. #include <libgearman-server/io.h>
  44. #include <libgearman-server/packet.h>
  45. #include <libgearman-server/struct/io.h>
  46. struct gearman_server_job_st;
  47. #ifdef __cplusplus
  48. extern "C" {
  49. #endif
  50. /**
  51. * @addtogroup gearman_server_con Connection Declarations
  52. * @ingroup gearman_server
  53. *
  54. * This is a low level interface for gearman server connections. This is used
  55. * internally by the server interface, so you probably want to look there first.
  56. *
  57. * @{
  58. */
  59. /**
  60. * Add a connection to a server thread. This goes into a list of connections
  61. * that is used later with server_thread_run, no socket I/O happens here.
  62. * @param thread Thread structure previously initialized with
  63. * gearman_server_thread_init.
  64. * @param fd File descriptor for a newly accepted connection.
  65. * @param data Application data pointer.
  66. * @return Gearman server connection pointer.
  67. */
  68. GEARMAN_API
  69. gearman_server_con_st *gearman_server_con_add(gearman_server_thread_st *thread, gearmand_con_st *dcon,
  70. gearmand_error_t& ret);
  71. /**
  72. * Attempt to free a server connection structure.
  73. */
  74. GEARMAN_API
  75. void gearman_server_con_attempt_free(gearman_server_con_st *con);
  76. /**
  77. * Actually free a server connection structure.
  78. */
  79. GEARMAN_API
  80. void gearman_server_con_free(gearman_server_con_st *con);
  81. /**
  82. * Get gearman connection pointer the server connection uses.
  83. */
  84. GEARMAN_API
  85. gearmand_io_st *gearman_server_con_con(gearman_server_con_st *con);
  86. /**
  87. * Get application data pointer.
  88. */
  89. GEARMAN_API
  90. gearmand_con_st *gearman_server_con_data(gearman_server_con_st *con);
  91. /**
  92. * Get client id.
  93. */
  94. GEARMAN_API
  95. const char *gearman_server_con_id(gearman_server_con_st *con);
  96. /**
  97. * Set client id.
  98. */
  99. GEARMAN_API
  100. void gearman_server_con_set_id(gearman_server_con_st *con, const char *id,
  101. const size_t size);
  102. /**
  103. * Free server worker struction with name for a server connection.
  104. */
  105. GEARMAN_API
  106. void gearman_server_con_free_worker(gearman_server_con_st *con,
  107. char *function_name,
  108. size_t function_name_size);
  109. /**
  110. * Free all server worker structures for a server connection.
  111. */
  112. GEARMAN_API
  113. void gearman_server_con_free_workers(gearman_server_con_st *con);
  114. /**
  115. * Add connection to the to_be_freed thread list.
  116. */
  117. GEARMAN_API
  118. void gearman_server_con_to_be_freed_add(gearman_server_con_st *con);
  119. /**
  120. * Pick out the next connection to free
  121. */
  122. GEARMAN_API
  123. gearman_server_con_st *
  124. gearman_server_con_to_be_freed_next(gearman_server_thread_st *thread);
  125. /**
  126. * Add connection to the io thread list.
  127. */
  128. GEARMAN_API
  129. void gearman_server_con_io_add(gearman_server_con_st *con);
  130. /**
  131. * Remove connection from the io thread list.
  132. */
  133. GEARMAN_API
  134. void gearman_server_con_io_remove(gearman_server_con_st *con);
  135. /**
  136. * Get next connection from the io thread list.
  137. */
  138. GEARMAN_API
  139. gearman_server_con_st *
  140. gearman_server_con_io_next(gearman_server_thread_st *thread);
  141. /**
  142. * Add connection to the proc thread list.
  143. */
  144. GEARMAN_API
  145. void gearman_server_con_proc_add(gearman_server_con_st *con);
  146. /**
  147. * Remove connection from the proc thread list.
  148. */
  149. GEARMAN_API
  150. void gearman_server_con_proc_remove(gearman_server_con_st *con);
  151. /**
  152. * Get next connection from the proc thread list.
  153. */
  154. GEARMAN_API
  155. gearman_server_con_st *
  156. gearman_server_con_proc_next(gearman_server_thread_st *thread);
  157. /**
  158. * Set protocol context pointer.
  159. * Add worker timeout for a connection tied to a job
  160. */
  161. GEARMAN_API
  162. gearmand_error_t gearman_server_con_add_job_timeout(gearman_server_con_st *con, gearman_server_job_st *job);
  163. /**
  164. * Delete timeout event for a server con
  165. */
  166. GEARMAN_API
  167. void gearman_server_con_delete_timeout(gearman_server_con_st *con);
  168. void gearman_server_con_protocol_release(gearman_server_con_st *con);
  169. gearman_server_con_st* build_gearman_server_con_st(void);
  170. void destroy_gearman_server_con_st(gearman_server_con_st* arg);
  171. void gearmand_connection_list_init(gearmand_connection_list_st *source, gearmand_event_watch_fn *watch_fn, void *watch_context);
  172. gearman_server_con_st *gearmand_ready(gearmand_connection_list_st *gearman);
  173. /** @} */
  174. #ifdef __cplusplus
  175. }
  176. #endif