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 /**
40  * @file
41  * @brief Defines, typedefs, and enums
42  */
43 
44 #pragma once
45 
46 #ifdef __cplusplus
47 #include <cstdlib>
48 #else
49 #include <stdlib.h>
50 #endif
51 
52 #include <libgearman-1.0/limits.h>
53 #include <libgearman-1.0/priority.h>
54 #include <libgearman-server/verbose.h>
55 
56 /**
57  * @addtogroup gearman_server_constants Constants
58  * @ingroup gearman_server
59  * @{
60  */
61 
62 /* Defines. */
63 #define GEARMAN_ARGS_BUFFER_SIZE 128
64 #define GEARMAN_CONF_DISPLAY_WIDTH 80
65 #define GEARMAN_CONF_MAX_OPTION_SHORT 128
66 #define GEARMAN_DEFAULT_BACKLOG 64
67 #define GEARMAN_DEFAULT_MAX_QUEUE_SIZE 0
68 #define GEARMAN_DEFAULT_SOCKET_RECV_SIZE 32768
69 #define GEARMAN_DEFAULT_SOCKET_SEND_SIZE 32768
70 #define GEARMAN_DEFAULT_SOCKET_TIMEOUT 10
71 #define GEARMAND_JOB_HANDLE_SIZE 64
72 #define GEARMAND_DEFAULT_HASH_SIZE 991
73 #define GEARMAN_MAX_COMMAND_ARGS 8
74 #define GEARMAN_MAX_FREE_SERVER_CLIENT 1000
75 #define GEARMAN_MAX_FREE_SERVER_CON 1000
76 #define GEARMAN_MAX_FREE_SERVER_JOB 1000
77 #define GEARMAN_MAX_FREE_SERVER_PACKET 2000
78 #define GEARMAN_MAX_FREE_SERVER_WORKER 1000
79 #define GEARMAN_OPTION_SIZE 64
80 #define GEARMAN_PACKET_HEADER_SIZE 12
81 #define GEARMAN_PIPE_BUFFER_SIZE 256
82 #define GEARMAN_RECV_BUFFER_SIZE 8192
83 #define GEARMAN_SEND_BUFFER_SIZE 8192
84 #define GEARMAN_SERVER_CON_ID_SIZE 128
85 #define GEARMAN_TEXT_RESPONSE_SIZE 8192
86 #define GEARMAN_MAGIC_MEMORY (void*)(0x000001)
87 
88 /** @} */
89 
90 /** @} */
91 
92 typedef enum
93 {
94   GEARMAND_CON_PACKET_IN_USE,
95   GEARMAND_CON_EXTERNAL_FD,
96   GEARMAND_CON_CLOSE_AFTER_FLUSH,
97   GEARMAND_CON_MAX
98 } gearmand_connection_options_t;
99 
100 
101 #ifdef __cplusplus
102 
103 struct gearman_server_thread_st;
104 struct gearman_server_st;
105 struct gearman_server_con_st;
106 struct gearmand_io_st;
107 
108 #endif
109 
110 #ifdef __cplusplus
111 extern "C" {
112 #endif
113 
114 /* Function types. */
115 typedef void (gearman_server_thread_run_fn)(gearman_server_thread_st *thread,
116                                             void *context);
117 
118 typedef gearmand_error_t (gearman_queue_add_fn)(gearman_server_st *server,
119                                                 void *context,
120                                                 const char *unique,
121                                                 size_t unique_size,
122                                                 const char *function_name,
123                                                 size_t function_name_size,
124                                                 const void *data,
125                                                 size_t data_size,
126                                                 gearman_job_priority_t priority,
127                                                 int64_t when);
128 
129 typedef gearmand_error_t (gearman_queue_flush_fn)(gearman_server_st *server,
130                                                  void *context);
131 
132 typedef gearmand_error_t (gearman_queue_done_fn)(gearman_server_st *server,
133                                                  void *context,
134                                                  const char *unique,
135                                                  size_t unique_size,
136                                                  const char *function_name,
137                                                  size_t function_name_size);
138 typedef gearmand_error_t (gearman_queue_replay_fn)(gearman_server_st *server,
139                                                    void *context,
140                                                    gearman_queue_add_fn *add_fn,
141                                                    void *add_context);
142 
143 typedef gearmand_error_t (gearmand_connection_add_fn)(gearman_server_con_st *con);
144 
145 typedef void (gearman_log_server_fn)(const char *line, gearmand_verbose_t verbose,
146                                      struct gearmand_thread_st *context);
147 
148 typedef gearmand_error_t (gearmand_event_watch_fn)(gearmand_io_st *con,
149                                                    short events, void *context);
150 
151 typedef void (gearmand_connection_protocol_context_free_fn)(gearman_server_con_st *con,
152                                                             void *context);
153 
154 typedef void (gearmand_log_fn)(const char *line, gearmand_verbose_t verbose,
155                               void *context);
156 
157 
158 /** @} */
159 
160 /**
161  * @addtogroup gearman_server_protocol Protocol Plugins
162  * @ingroup gearman_server
163  */
164 
165 /**
166  * @addtogroup gearman_server_queue Queue Plugins
167  * @ingroup gearman_server
168  */
169 
170 #ifdef __cplusplus
171 }
172 #endif
173