2
Example code to show how to send a string to a function called "reverse" and print the results.
8
#include <libgearman/gearman.h>
12
gearman_client_st *client= gearman_client_create(NULL);
14
gearman_return_t ret= gearman_client_add_server(client, "localhost", 0);
15
if (gearman_failed(ret))
20
gearman_argument_t value= gearman_argument_make(0, 0, "Reverse Me", strlen("Reverse Me"));
22
gearman_task_st *task= gearman_execute(client,
23
"reverse", strlen("reverse"), // function
24
NULL, 0, // no unique value provided
28
if (task == NULL) // If gearman_execute() can return NULL on error
30
fprintf(stderr, "Error: %s\n", gearman_client_error(client));
31
gearman_client_free(client);
35
// Make sure the task was run successfully
36
if (gearman_success(gearman_task_return(task)))
39
gearman_result_st *result= gearman_task_result(task);
40
printf("%.*s\n", (int)gearman_result_size(result), gearman_result_value(result));
43
gearman_client_free(client);