17 #include "plugin/gearman_udf/gman_do.h"
18 #include "plugin/gearman_udf/function_map.h"
21 using namespace drizzled;
25 static void *_do_malloc(
size_t size,
void *arg)
28 return item->realloc(size);
32 Item_func_gman_do::~Item_func_gman_do()
34 if (options & GMAN_DO_OPTIONS_CLIENT)
35 gearman_client_free(&client);
47 char job_handle[GEARMAN_JOB_HANDLE_SIZE];
49 if (arg_count < 1 || arg_count > 3 || !(
function= args[0]->val_str(str)))
55 if (arg_count > 1 && (res= args[1]->val_str(str)) != NULL)
58 workload_size= res->length();
66 if (arg_count == 3 && (res= args[2]->val_str(str)) != NULL)
71 if (!(options & GMAN_DO_OPTIONS_CLIENT))
73 if (!GetFunctionMap().
get(
string(function->ptr()), &client))
79 gearman_client_set_workload_malloc_fn(&client, _do_malloc,
this);
80 options= (gman_do_options_t)(options | GMAN_DO_OPTIONS_CLIENT);
83 if (options & GMAN_DO_OPTIONS_BACKGROUND)
85 if (options & GMAN_DO_OPTIONS_HIGH)
87 ret= gearman_client_do_high_background(&client, function->ptr(), unique,
88 workload, workload_size,
91 else if (options & GMAN_DO_OPTIONS_LOW)
93 ret= gearman_client_do_low_background(&client, function->ptr(), unique,
94 workload, workload_size,
99 ret= gearman_client_do_background(&client, function->ptr(), unique,
100 workload, workload_size, job_handle);
103 if (ret == GEARMAN_SUCCESS)
105 result_size= strlen(job_handle);
106 buffer.realloc(result_size);
107 buffer.length(result_size);
108 memcpy(buffer.ptr(), job_handle, result_size);
113 if (options & GMAN_DO_OPTIONS_HIGH)
115 (void) gearman_client_do_high(&client, function->ptr(), unique, workload,
116 workload_size, &result_size, &ret);
118 else if (options & GMAN_DO_OPTIONS_LOW)
120 (void) gearman_client_do_low(&client, function->ptr(), unique, workload,
121 workload_size, &result_size, &ret);
125 (void) gearman_client_do(&client, function->ptr(), unique, workload,
126 workload_size, &result_size, &ret);
130 if (ret != GEARMAN_SUCCESS)
140 void *Item_func_gman_do::realloc(
size_t size)
142 buffer.realloc(size);
drizzled::String * val_str(drizzled::String *)