00001 /* Gearman server and library 00002 * Copyright (C) 2008 Brian Aker, Eric Day 00003 * All rights reserved. 00004 * 00005 * Use and distribution licensed under the BSD license. See 00006 * the COPYING file in the parent directory for full text. 00007 */ 00008 00014 #ifndef __GEARMAN_SERVER_STRUCTS_H__ 00015 #define __GEARMAN_SERVER_STRUCTS_H__ 00016 00017 #ifdef __cplusplus 00018 extern "C" { 00019 #endif 00020 00024 struct gearman_server_st 00025 { 00026 gearman_server_options_t options; 00027 bool shutdown; 00028 bool shutdown_graceful; 00029 bool proc_wakeup; 00030 bool proc_shutdown; 00031 uint8_t job_retries; 00032 uint32_t job_handle_count; 00033 uint32_t thread_count; 00034 uint32_t function_count; 00035 uint32_t job_count; 00036 uint32_t unique_count; 00037 uint32_t free_packet_count; 00038 uint32_t free_job_count; 00039 uint32_t free_client_count; 00040 uint32_t free_worker_count; 00041 gearman_st *gearman; 00042 gearman_server_thread_st *thread_list; 00043 gearman_server_function_st *function_list; 00044 gearman_server_packet_st *free_packet_list; 00045 gearman_server_job_st *free_job_list; 00046 gearman_server_client_st *free_client_list; 00047 gearman_server_worker_st *free_worker_list; 00048 gearman_log_fn *log_fn; 00049 const void *log_context; 00050 const void *queue_context; 00051 gearman_queue_add_fn *queue_add_fn; 00052 gearman_queue_flush_fn *queue_flush_fn; 00053 gearman_queue_done_fn *queue_done_fn; 00054 gearman_queue_replay_fn *queue_replay_fn; 00055 gearman_st gearman_static; 00056 pthread_mutex_t proc_lock; 00057 pthread_cond_t proc_cond; 00058 pthread_t proc_id; 00059 char job_handle_prefix[GEARMAN_JOB_HANDLE_SIZE]; 00060 gearman_server_job_st *job_hash[GEARMAN_JOB_HASH_SIZE]; 00061 gearman_server_job_st *unique_hash[GEARMAN_JOB_HASH_SIZE]; 00062 }; 00063 00067 struct gearman_server_thread_st 00068 { 00069 gearman_server_thread_options_t options; 00070 uint32_t con_count; 00071 uint32_t io_count; 00072 uint32_t proc_count; 00073 uint32_t free_con_count; 00074 uint32_t free_packet_count; 00075 gearman_st *gearman; 00076 gearman_server_st *server; 00077 gearman_server_thread_st *next; 00078 gearman_server_thread_st *prev; 00079 gearman_log_fn *log_fn; 00080 const void *log_context; 00081 gearman_server_thread_run_fn *run_fn; 00082 void *run_fn_arg; 00083 gearman_server_con_st *con_list; 00084 gearman_server_con_st *io_list; 00085 gearman_server_con_st *proc_list; 00086 gearman_server_con_st *free_con_list; 00087 gearman_server_packet_st *free_packet_list; 00088 gearman_st gearman_static; 00089 pthread_mutex_t lock; 00090 }; 00091 00095 struct gearman_server_con_st 00096 { 00097 gearman_con_st con; /* This must be the first struct member. */ 00098 gearman_server_con_options_t options; 00099 gearman_return_t ret; 00100 bool io_list; 00101 bool proc_list; 00102 bool proc_removed; 00103 uint32_t io_packet_count; 00104 uint32_t proc_packet_count; 00105 uint32_t worker_count; 00106 uint32_t client_count; 00107 gearman_server_thread_st *thread; 00108 gearman_server_con_st *next; 00109 gearman_server_con_st *prev; 00110 gearman_server_packet_st *packet; 00111 gearman_server_packet_st *io_packet_list; 00112 gearman_server_packet_st *io_packet_end; 00113 gearman_server_packet_st *proc_packet_list; 00114 gearman_server_packet_st *proc_packet_end; 00115 gearman_server_con_st *io_next; 00116 gearman_server_con_st *io_prev; 00117 gearman_server_con_st *proc_next; 00118 gearman_server_con_st *proc_prev; 00119 gearman_server_worker_st *worker_list; 00120 gearman_server_client_st *client_list; 00121 const char *host; 00122 const char *port; 00123 char id[GEARMAN_SERVER_CON_ID_SIZE]; 00124 }; 00125 00129 struct gearman_server_packet_st 00130 { 00131 gearman_packet_st packet; 00132 gearman_server_packet_st *next; 00133 }; 00134 00138 struct gearman_server_function_st 00139 { 00140 gearman_server_function_options_t options; 00141 uint32_t worker_count; 00142 uint32_t job_count; 00143 uint32_t job_total; 00144 uint32_t job_running; 00145 uint32_t max_queue_size; 00146 size_t function_name_size; 00147 gearman_server_st *server; 00148 gearman_server_function_st *next; 00149 gearman_server_function_st *prev; 00150 char *function_name; 00151 gearman_server_worker_st *worker_list; 00152 gearman_server_job_st *job_list[GEARMAN_JOB_PRIORITY_MAX]; 00153 gearman_server_job_st *job_end[GEARMAN_JOB_PRIORITY_MAX]; 00154 }; 00155 00159 struct gearman_server_client_st 00160 { 00161 gearman_server_client_options_t options; 00162 gearman_server_con_st *con; 00163 gearman_server_client_st *con_next; 00164 gearman_server_client_st *con_prev; 00165 gearman_server_job_st *job; 00166 gearman_server_client_st *job_next; 00167 gearman_server_client_st *job_prev; 00168 }; 00169 00173 struct gearman_server_worker_st 00174 { 00175 gearman_server_worker_options_t options; 00176 uint32_t job_count; 00177 uint32_t timeout; 00178 gearman_server_con_st *con; 00179 gearman_server_worker_st *con_next; 00180 gearman_server_worker_st *con_prev; 00181 gearman_server_function_st *function; 00182 gearman_server_worker_st *function_next; 00183 gearman_server_worker_st *function_prev; 00184 gearman_server_job_st *job_list; 00185 }; 00186 00190 struct gearman_server_job_st 00191 { 00192 uint8_t retries; 00193 gearman_server_job_options_t options; 00194 gearman_job_priority_t priority; 00195 uint32_t job_handle_key; 00196 uint32_t unique_key; 00197 uint32_t client_count; 00198 uint32_t numerator; 00199 uint32_t denominator; 00200 size_t data_size; 00201 gearman_server_st *server; 00202 gearman_server_job_st *next; 00203 gearman_server_job_st *prev; 00204 gearman_server_job_st *unique_next; 00205 gearman_server_job_st *unique_prev; 00206 gearman_server_job_st *worker_next; 00207 gearman_server_job_st *worker_prev; 00208 gearman_server_function_st *function; 00209 gearman_server_job_st *function_next; 00210 const void *data; 00211 gearman_server_client_st *client_list; 00212 gearman_server_worker_st *worker; 00213 char job_handle[GEARMAN_JOB_HANDLE_SIZE]; 00214 char unique[GEARMAN_UNIQUE_SIZE]; 00215 }; 00216 00220 struct gearmand_st 00221 { 00222 gearmand_options_t options; 00223 gearman_verbose_t verbose; 00224 gearman_return_t ret; 00225 int backlog; 00226 uint32_t port_count; 00227 uint32_t threads; 00228 uint32_t thread_count; 00229 uint32_t free_dcon_count; 00230 uint32_t max_thread_free_dcon_count; 00231 int wakeup_fd[2]; 00232 const char *host; 00233 gearman_log_fn *log_fn; 00234 const void *log_context; 00235 struct event_base *base; 00236 gearmand_port_st *port_list; 00237 gearmand_thread_st *thread_list; 00238 gearmand_thread_st *thread_add_next; 00239 gearmand_con_st *free_dcon_list; 00240 gearman_server_st server; 00241 struct event wakeup_event; 00242 }; 00243 00247 struct gearmand_port_st 00248 { 00249 in_port_t port; 00250 uint32_t listen_count; 00251 gearmand_st *gearmand; 00252 gearman_con_add_fn *add_fn; 00253 int *listen_fd; 00254 struct event *listen_event; 00255 }; 00256 00260 struct gearmand_thread_st 00261 { 00262 gearmand_thread_options_t options; 00263 uint32_t count; 00264 uint32_t dcon_count; 00265 uint32_t dcon_add_count; 00266 uint32_t free_dcon_count; 00267 int wakeup_fd[2]; 00268 gearmand_thread_st *next; 00269 gearmand_thread_st *prev; 00270 gearmand_st *gearmand; 00271 struct event_base *base; 00272 gearmand_con_st *dcon_list; 00273 gearmand_con_st *dcon_add_list; 00274 gearmand_con_st *free_dcon_list; 00275 gearman_server_thread_st server_thread; 00276 struct event wakeup_event; 00277 pthread_t id; 00278 pthread_mutex_t lock; 00279 }; 00280 00284 struct gearmand_con_st 00285 { 00286 short last_events; 00287 int fd; 00288 gearmand_thread_st *thread; 00289 gearmand_con_st *next; 00290 gearmand_con_st *prev; 00291 gearman_server_con_st *server_con; 00292 gearman_con_st *con; 00293 gearman_con_add_fn *add_fn; 00294 struct event event; 00295 char host[NI_MAXHOST]; 00296 char port[NI_MAXSERV]; 00297 }; 00298 00302 struct gearman_conf_st 00303 { 00304 gearman_conf_options_t options; 00305 gearman_return_t last_return; 00306 int last_errno; 00307 size_t module_count; 00308 size_t option_count; 00309 size_t short_count; 00310 gearman_conf_module_st **module_list; 00311 gearman_conf_option_st *option_list; 00312 struct option *option_getopt; 00313 char option_short[GEARMAN_CONF_MAX_OPTION_SHORT]; 00314 char last_error[GEARMAN_MAX_ERROR_SIZE]; 00315 }; 00316 00320 struct gearman_conf_option_st 00321 { 00322 size_t value_count; 00323 gearman_conf_module_st *module; 00324 const char *name; 00325 const char *value_name; 00326 const char *help; 00327 char **value_list; 00328 }; 00329 00333 struct gearman_conf_module_st 00334 { 00335 gearman_conf_module_options_t options; 00336 size_t current_option; 00337 size_t current_value; 00338 gearman_conf_st *conf; 00339 const char *name; 00340 }; 00341 00342 #ifdef __cplusplus 00343 } 00344 #endif 00345 00346 #endif /* __GEARMAN_SERVER_STRUCTS_H__ */