gearman_client_do_example.c 916 B

123456789101112131415161718192021222324252627282930313233343536373839
  1. /*
  2. # Gearman server and library
  3. # Copyright (C) 2012 Data Differential, http://datadifferential.com/
  4. # All rights reserved.
  5. #
  6. # Use and distribution licensed under the BSD license. See
  7. # the COPYING file in this directory for full text.
  8. */
  9. #include <string.h>
  10. #include <stdlib.h>
  11. #include <libgearman/gearman.h>
  12. int main(void)
  13. {
  14. gearman_client_st *client= gearman_client_create(NULL);
  15. gearman_return_t ret= gearman_client_add_server(client, "localhost", 0);
  16. if (gearman_failed(ret))
  17. {
  18. return EXIT_FAILURE;
  19. }
  20. size_t result_size;
  21. gearman_return_t rc;
  22. void *value= gearman_client_do(client, "reverse_function", "unique_value",
  23. "my string to reverse", strlen("my string to reverse"),
  24. &result_size, &rc);
  25. if (gearman_success(rc))
  26. {
  27. // Make use of value
  28. }
  29. free(value);
  30. gearman_client_free(client);
  31. return 0;
  32. }