gearman_client_do_background_example.c 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041
  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 <stdio.h>
  12. #include <libgearman-1.0/gearman.h>
  13. int main(void)
  14. {
  15. gearman_client_st *client= gearman_client_create(NULL);
  16. gearman_return_t ret= gearman_client_add_server(client, "localhost", 0);
  17. if (gearman_failed(ret))
  18. {
  19. return EXIT_FAILURE;
  20. }
  21. gearman_job_handle_t job_handle;
  22. gearman_return_t rc= gearman_client_do_background(client,
  23. "reverse_function",
  24. "unique_value",
  25. "my string to reverse", strlen("my string to reverse"),
  26. job_handle);
  27. if (gearman_success(rc))
  28. {
  29. // Make use of value
  30. printf("%s\n", job_handle);
  31. }
  32. gearman_client_free(client);
  33. return 0;
  34. }