universal.hpp 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154
  1. /* vim:expandtab:shiftwidth=2:tabstop=2:smarttab:
  2. *
  3. * Gearmand client and server library.
  4. *
  5. * Copyright (C) 2011 Data Differential, http://datadifferential.com/
  6. * Copyright (C) 2008 Brian Aker, Eric Day
  7. * All rights reserved.
  8. *
  9. * Redistribution and use in source and binary forms, with or without
  10. * modification, are permitted provided that the following conditions are
  11. * met:
  12. *
  13. * * Redistributions of source code must retain the above copyright
  14. * notice, this list of conditions and the following disclaimer.
  15. *
  16. * * Redistributions in binary form must reproduce the above
  17. * copyright notice, this list of conditions and the following disclaimer
  18. * in the documentation and/or other materials provided with the
  19. * distribution.
  20. *
  21. * * The names of its contributors may not be used to endorse or
  22. * promote products derived from this software without specific prior
  23. * written permission.
  24. *
  25. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
  26. * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
  27. * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
  28. * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
  29. * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
  30. * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
  31. * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
  32. * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
  33. * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  34. * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
  35. * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  36. *
  37. */
  38. #pragma once
  39. // Get next connection that is ready for I/O.
  40. GEARMAN_LOCAL
  41. gearman_connection_st *gearman_ready(gearman_universal_st&);
  42. GEARMAN_LOCAL
  43. void gearman_universal_initialize(gearman_universal_st &self, const gearman_universal_options_t *options= NULL);
  44. GEARMAN_LOCAL
  45. void gearman_universal_clone(gearman_universal_st &destination, const gearman_universal_st &source);
  46. GEARMAN_LOCAL
  47. void gearman_universal_free(gearman_universal_st &gearman);
  48. GEARMAN_LOCAL
  49. void gearman_free_all_packets(gearman_universal_st &gearman);
  50. GEARMAN_LOCAL
  51. bool gearman_request_option(gearman_universal_st &universal, gearman_string_t &option);
  52. GEARMAN_LOCAL
  53. gearman_return_t gearman_universal_set_option(gearman_universal_st &self, gearman_universal_options_t option, bool value);
  54. GEARMAN_LOCAL
  55. void gearman_set_log_fn(gearman_universal_st &self, gearman_log_fn *function, void *context, gearman_verbose_t verbose);
  56. GEARMAN_LOCAL
  57. void gearman_universal_set_timeout(gearman_universal_st &self, int timeout);
  58. GEARMAN_LOCAL
  59. int gearman_universal_timeout(gearman_universal_st &self);
  60. GEARMAN_LOCAL
  61. void gearman_universal_set_namespace(gearman_universal_st &self, const char *namespace_key, size_t namespace_key_size);
  62. GEARMAN_LOCAL
  63. void gearman_reset(gearman_universal_st& universal);
  64. // Flush the send buffer for all connections.
  65. GEARMAN_LOCAL
  66. gearman_return_t gearman_flush_all(gearman_universal_st&);
  67. /**
  68. * Set custom memory allocation function for workloads. Normally gearman uses
  69. * the standard system malloc to allocate memory used with workloads. The
  70. * provided function will be used instead.
  71. */
  72. GEARMAN_LOCAL
  73. void gearman_set_workload_malloc_fn(gearman_universal_st&,
  74. gearman_malloc_fn *function,
  75. void *context);
  76. /**
  77. * Set custom memory free function for workloads. Normally gearman uses the
  78. * standard system free to free memory used with workloads. The provided
  79. * function will be used instead.
  80. */
  81. GEARMAN_LOCAL
  82. void gearman_set_workload_free_fn(gearman_universal_st&,
  83. gearman_free_fn *function,
  84. void *context);
  85. // Free all connections for a gearman structure.
  86. GEARMAN_LOCAL
  87. void gearman_free_all_cons(gearman_universal_st&);
  88. // Test echo with all connections.
  89. GEARMAN_LOCAL
  90. gearman_return_t gearman_echo(gearman_universal_st&, const void *workload, size_t workload_size);
  91. /**
  92. * Wait for I/O on connections.
  93. *
  94. */
  95. GEARMAN_LOCAL
  96. gearman_return_t gearman_wait(gearman_universal_st&);
  97. GEARMAN_LOCAL
  98. void gearman_nap(gearman_universal_st &self);
  99. GEARMAN_LOCAL
  100. void gearman_nap(int arg);
  101. static inline void gearman_universal_add_options(gearman_universal_st &self, gearman_universal_options_t options)
  102. {
  103. (void)gearman_universal_set_option(self, options, true);
  104. }
  105. static inline void gearman_universal_remove_options(gearman_universal_st &self, gearman_universal_options_t options)
  106. {
  107. (void)gearman_universal_set_option(self, options, false);
  108. }
  109. static inline bool gearman_universal_is_non_blocking(gearman_universal_st &self)
  110. {
  111. return self.options.non_blocking;
  112. }
  113. static inline const char *gearman_universal_error(const gearman_universal_st &self)
  114. {
  115. if (self.error.last_error[0] == 0)
  116. return NULL;
  117. return static_cast<const char *>(self.error.last_error);
  118. }
  119. static inline gearman_return_t gearman_universal_error_code(const gearman_universal_st &self)
  120. {
  121. return self.error.rc;
  122. }
  123. static inline int gearman_universal_errno(const gearman_universal_st &self)
  124. {
  125. return self.error.last_errno;
  126. }