~clint-fewbar/ubuntu/precise/gearmand/drop-unneeded-patches

« back to all changes in this revision

Viewing changes to docs/libgearman/examples/gearman_execute_example.c

  • Committer: Bazaar Package Importer
  • Author(s): Monty Taylor
  • Date: 2009-09-28 21:43:31 UTC
  • mto: (1.2.3 upstream) (6.1.1 sid)
  • mto: This revision was merged to the branch mainline in revision 5.
  • Revision ID: james.westby@ubuntu.com-20090928214331-9bku0d3v1b1ypgp4
ImportĀ upstreamĀ versionĀ 0.10

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/*
2
 
  Example code to show how to send a string to a function called "reverse" and print the results.
3
 
*/
4
 
 
5
 
#include <string.h>
6
 
#include <stdlib.h>
7
 
#include <stdio.h>
8
 
#include <libgearman/gearman.h>
9
 
 
10
 
int main(void)
11
 
{
12
 
  gearman_client_st *client= gearman_client_create(NULL);
13
 
 
14
 
  gearman_return_t ret= gearman_client_add_server(client, "localhost", 0);
15
 
  if (gearman_failed(ret))
16
 
  {
17
 
    return EXIT_FAILURE;
18
 
  }
19
 
 
20
 
  gearman_argument_t value= gearman_argument_make(0, 0, "Reverse Me", strlen("Reverse Me"));
21
 
 
22
 
  gearman_task_st *task= gearman_execute(client, 
23
 
                                         "reverse", strlen("reverse"),  // function
24
 
                                         NULL, 0,  // no unique value provided
25
 
                                         NULL, 
26
 
                                         &value, 0);
27
 
 
28
 
  if (task == NULL) // If gearman_execute() can return NULL on error
29
 
  {
30
 
    fprintf(stderr, "Error: %s\n", gearman_client_error(client));
31
 
    gearman_client_free(client);
32
 
    return EXIT_FAILURE;
33
 
  }
34
 
 
35
 
  // Make sure the task was run successfully
36
 
  if (gearman_success(gearman_task_return(task)))
37
 
  {
38
 
    // Make use of value
39
 
    gearman_result_st *result= gearman_task_result(task);
40
 
    printf("%.*s\n", (int)gearman_result_size(result), gearman_result_value(result));
41
 
  }
42
 
 
43
 
  gearman_client_free(client);
44
 
 
45
 
  return EXIT_SUCCESS;
46
 
}