gearmand.h 6.1 KB

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