gearmand.h 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202
  1. /* vim:expandtab:shiftwidth=2:tabstop=2:smarttab:
  2. *
  3. * Gearmand client and server library.
  4. *
  5. * Copyright (C) 2011-2013 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 Gearmand Declarations
  41. */
  42. #pragma once
  43. #include <netinet/in.h>
  44. #include <stdlib.h>
  45. #include <poll.h>
  46. #include <event.h>
  47. #ifdef HAVE_LIBEVENT2
  48. #include <event2/event.h>
  49. #include <event2/thread.h>
  50. #endif
  51. #include <libgearman-1.0/visibility.h>
  52. #include <libgearman-1.0/protocol.h>
  53. #include <libgearman-server/error.h>
  54. #include <libgearman-server/constants.h>
  55. #include <libgearman-server/wakeup.h>
  56. #include <libgearman-server/log.h>
  57. #include <libgearman-server/packet.h>
  58. #include <libgearman-server/connection.h>
  59. #ifdef __cplusplus
  60. #include <libgearman-server/connection.hpp>
  61. #endif
  62. #include <libgearman-server/function.h>
  63. #include <libgearman-server/client.h>
  64. #include <libgearman-server/worker.h>
  65. #include <libgearman-server/job.h>
  66. #include <libgearman-server/thread.h>
  67. #include <libgearman-server/server.h>
  68. #include <libgearman-server/gearmand_thread.h>
  69. #include <libgearman-server/gearmand_con.h>
  70. #include <libgearman-server/struct/gearmand.h>
  71. #include <libgearman-server/text.h>
  72. #include <libgearman-server/config.h>
  73. #ifdef __cplusplus
  74. extern "C" {
  75. #endif
  76. /**
  77. * @addtogroup gearmand Gearmand Declarations
  78. *
  79. * This is a server implementation using the gearman_server interface.
  80. *
  81. * @{
  82. */
  83. GEARMAN_API
  84. gearmand_st *Gearmand(void);
  85. #define Server (&(Gearmand()->server))
  86. /**
  87. * Create a server instance.
  88. * @param host Host for the server to listen on.
  89. * @param port Port for the server to listen on.
  90. * @return Pointer to an allocated gearmand structure.
  91. */
  92. GEARMAN_API
  93. gearmand_st *gearmand_create(gearmand_config_st *config,
  94. const char *host,
  95. uint32_t threads,
  96. int backlog,
  97. const uint32_t job_retries,
  98. const char *job_handle_prefix,
  99. uint8_t worker_wakeup,
  100. gearmand_log_fn *function, void *log_context, const gearmand_verbose_t verbose,
  101. bool round_robin,
  102. bool exceptions_,
  103. uint32_t hashtable_buckets);
  104. /**
  105. * Free resources used by a server instace.
  106. * @param gearmand Server instance structure previously initialized with
  107. * gearmand_create.
  108. */
  109. GEARMAN_API
  110. void gearmand_free(gearmand_st *gearmand);
  111. GEARMAN_API
  112. gearman_server_st *gearmand_server(gearmand_st *gearmand);
  113. /**
  114. * Add a port to listen on when starting server with optional callback.
  115. * @param gearmand Server instance structure previously initialized with
  116. * gearmand_create.
  117. * @param port Port for the server to listen on.
  118. * @param function Optional callback function that is called when a connection
  119. has been accepted on the given port.
  120. * @return Standard gearman return value.
  121. */
  122. GEARMAN_API
  123. gearmand_error_t gearmand_port_add(gearmand_st *gearmand,
  124. const char *port,
  125. gearmand_connection_add_fn*,
  126. gearmand_connection_remove_fn*);
  127. /**
  128. * Run the server instance.
  129. * @param gearmand Server instance structure previously initialized with
  130. * gearmand_create.
  131. * @return Standard gearman return value.
  132. */
  133. GEARMAN_API
  134. gearmand_error_t gearmand_run(gearmand_st *gearmand);
  135. bool gearmand_exceptions(gearmand_st *gearmand);
  136. /**
  137. * Interrupt a running gearmand server from another thread. You should only
  138. * call this when another thread is currently running gearmand_run() and you
  139. * want to wakeup the server with the given event.
  140. * @param gearmand Server instance structure previously initialized with
  141. * gearmand_create.
  142. * @param wakeup Wakeup event to send to running gearmand.
  143. */
  144. GEARMAN_API
  145. void gearmand_wakeup(gearmand_st *gearmand, gearmand_wakeup_t wakeup);
  146. GEARMAN_API
  147. const char *gearmand_version(void);
  148. GEARMAN_API
  149. const char *gearmand_bugreport(void);
  150. GEARMAN_API
  151. const char *gearmand_verbose_name(gearmand_verbose_t verbose);
  152. GEARMAN_API
  153. gearmand_error_t gearmand_set_socket_keepalive(gearmand_st *gearmand, bool arg);
  154. GEARMAN_API
  155. gearmand_error_t gearmand_set_socket_keepalive_idle(gearmand_st *gearmand, int arg);
  156. GEARMAN_API
  157. gearmand_error_t gearmand_set_socket_keepalive_interval(gearmand_st *gearmand, int arg);
  158. GEARMAN_API
  159. gearmand_error_t gearmand_set_socket_keepalive_count(gearmand_st *gearmand, int arg);
  160. /** @} */
  161. #ifdef __cplusplus
  162. }
  163. #endif
  164. #ifdef __cplusplus
  165. GEARMAN_API
  166. bool gearmand_verbose_check(const char *name, gearmand_verbose_t& level);
  167. #endif