constants.h 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192
  1. /* vim:expandtab:shiftwidth=2:tabstop=2:smarttab:
  2. *
  3. * Gearmand client and server library.
  4. *
  5. * Copyright (C) 2011 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. #pragma once
  39. #include <libgearman/priority.h>
  40. #include <libgearman/protocol.h>
  41. #include <libgearman/return.h>
  42. #ifdef __cplusplus
  43. extern "C" {
  44. #endif
  45. /**
  46. * @addtogroup gearman_constants Constants
  47. * @ingroup gearman_universal
  48. * @ingroup gearman_client
  49. * @ingroup gearman_worker
  50. * @{
  51. */
  52. /* Defines. */
  53. #define GEARMAN_ARGS_BUFFER_SIZE 128
  54. #define GEARMAN_DEFAULT_SOCKET_RECV_SIZE 32768
  55. #define GEARMAN_DEFAULT_SOCKET_SEND_SIZE 32768
  56. #define GEARMAN_DEFAULT_SOCKET_TIMEOUT 10
  57. #define GEARMAN_DEFAULT_TCP_HOST "127.0.0.1"
  58. #define GEARMAN_JOB_HANDLE_SIZE 64
  59. #define GEARMAN_MAXIMUM_INTEGER_DISPLAY_LENGTH 20
  60. #define GEARMAN_MAX_COMMAND_ARGS 8
  61. #define GEARMAN_MAX_ERROR_SIZE 1024
  62. #define GEARMAN_OPTION_SIZE 64
  63. #define GEARMAN_PACKET_HEADER_SIZE 12
  64. #define GEARMAN_RECV_BUFFER_SIZE 8192
  65. #define GEARMAN_SEND_BUFFER_SIZE 8192
  66. #define GEARMAN_UNIQUE_SIZE 64
  67. #define GEARMAN_WORKER_WAIT_TIMEOUT (10 * 1000) /* Milliseconds */
  68. /**
  69. * Verbosity levels.
  70. */
  71. typedef enum
  72. {
  73. GEARMAN_VERBOSE_NEVER,
  74. GEARMAN_VERBOSE_FATAL,
  75. GEARMAN_VERBOSE_ERROR,
  76. GEARMAN_VERBOSE_INFO,
  77. GEARMAN_VERBOSE_DEBUG,
  78. GEARMAN_VERBOSE_CRAZY,
  79. GEARMAN_VERBOSE_MAX
  80. } gearman_verbose_t;
  81. /** @} */
  82. /**
  83. * @ingroup gearman_universal
  84. * Options for gearman_universal_st.
  85. */
  86. typedef enum
  87. {
  88. GEARMAN_NON_BLOCKING,
  89. GEARMAN_DONT_TRACK_PACKETS,
  90. GEARMAN_MAX
  91. } gearman_universal_options_t;
  92. /**
  93. * @ingroup gearman_con
  94. * Options for gearman_connection_st.
  95. */
  96. typedef enum
  97. {
  98. GEARMAN_CON_READY,
  99. GEARMAN_CON_PACKET_IN_USE,
  100. GEARMAN_CON_EXTERNAL_FD,
  101. GEARMAN_CON_IGNORE_LOST_CONNECTION,
  102. GEARMAN_CON_CLOSE_AFTER_FLUSH,
  103. GEARMAN_CON_MAX
  104. } gearman_connection_options_t;
  105. /**
  106. * @ingroup gearman_client
  107. * Options for gearman_client_st.
  108. */
  109. typedef enum
  110. {
  111. GEARMAN_CLIENT_ALLOCATED= (1 << 0),
  112. GEARMAN_CLIENT_NON_BLOCKING= (1 << 1),
  113. GEARMAN_CLIENT_TASK_IN_USE= (1 << 2),
  114. GEARMAN_CLIENT_UNBUFFERED_RESULT= (1 << 3),
  115. GEARMAN_CLIENT_NO_NEW= (1 << 4),
  116. GEARMAN_CLIENT_FREE_TASKS= (1 << 5),
  117. GEARMAN_CLIENT_MAX= (1 << 6)
  118. } gearman_client_options_t;
  119. /**
  120. * @ingroup gearman_worker
  121. * Options for gearman_worker_st.
  122. */
  123. typedef enum
  124. {
  125. GEARMAN_WORKER_ALLOCATED= (1 << 0),
  126. GEARMAN_WORKER_NON_BLOCKING= (1 << 1),
  127. GEARMAN_WORKER_PACKET_INIT= (1 << 2),
  128. GEARMAN_WORKER_GRAB_JOB_IN_USE= (1 << 3),
  129. GEARMAN_WORKER_PRE_SLEEP_IN_USE= (1 << 4),
  130. GEARMAN_WORKER_WORK_JOB_IN_USE= (1 << 5),
  131. GEARMAN_WORKER_CHANGE= (1 << 6),
  132. GEARMAN_WORKER_GRAB_UNIQ= (1 << 7),
  133. GEARMAN_WORKER_TIMEOUT_RETURN= (1 << 8),
  134. GEARMAN_WORKER_GRAB_ALL= (1 << 9),
  135. GEARMAN_WORKER_MAX= (1 << 10)
  136. } gearman_worker_options_t;
  137. /* Types. */
  138. typedef struct gearman_packet_st gearman_packet_st;
  139. typedef struct gearman_task_st gearman_task_st;
  140. typedef struct gearman_client_st gearman_client_st;
  141. typedef struct gearman_job_st gearman_job_st;
  142. typedef struct gearman_worker_st gearman_worker_st;
  143. typedef struct gearman_allocator_t gearman_allocator_t;
  144. typedef struct gearman_task_attr_t gearman_task_attr_t;
  145. typedef struct gearman_result_st gearman_result_st;
  146. typedef struct gearman_string_t gearman_string_t;
  147. typedef struct gearman_argument_t gearman_argument_t;
  148. // Custom allocators
  149. typedef void* (gearman_malloc_fn)(size_t size, void *context);
  150. typedef void* (gearman_realloc_fn)(void *ptr, size_t size, void *context);
  151. typedef void* (gearman_calloc_fn)(size_t nelm, size_t size, void *context);
  152. typedef void (gearman_free_fn)(void *ptr, void *context);
  153. typedef gearman_return_t (gearman_parse_server_fn)(const char *host, in_port_t port, void *context);
  154. typedef void (gearman_task_context_free_fn)(gearman_task_st *task, void *context);
  155. typedef void (gearman_log_fn)(const char *line, gearman_verbose_t verbose, void *context);
  156. // Worker types
  157. typedef void* (gearman_worker_fn)(gearman_job_st *job, void *context,
  158. size_t *result_size,
  159. gearman_return_t *ret_ptr);
  160. typedef gearman_return_t (gearman_function_fn)(gearman_job_st *job, void *worker_context);
  161. typedef struct gearman_aggregator_st gearman_aggregator_st;
  162. typedef gearman_return_t (gearman_aggregator_fn)(gearman_aggregator_st *, gearman_task_st *, gearman_result_st *);
  163. /** @} */
  164. #ifdef __cplusplus
  165. }
  166. #endif