connection.h 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164
  1. /* Gearman server and library
  2. * Copyright (C) 2008 Brian Aker, Eric Day
  3. * All rights reserved.
  4. *
  5. * Use and distribution licensed under the BSD license. See
  6. * the COPYING file in the parent directory for full text.
  7. */
  8. /**
  9. * @file
  10. * @brief Connection Declarations
  11. */
  12. #pragma once
  13. #include <libgearman-server/io.h>
  14. #include <libgearman-server/packet.h>
  15. #include <libgearman-server/struct/io.h>
  16. struct gearman_server_job_st;
  17. #ifdef __cplusplus
  18. extern "C" {
  19. #endif
  20. /**
  21. * @addtogroup gearman_server_con Connection Declarations
  22. * @ingroup gearman_server
  23. *
  24. * This is a low level interface for gearman server connections. This is used
  25. * internally by the server interface, so you probably want to look there first.
  26. *
  27. * @{
  28. */
  29. /**
  30. * Add a connection to a server thread. This goes into a list of connections
  31. * that is used later with server_thread_run, no socket I/O happens here.
  32. * @param thread Thread structure previously initialized with
  33. * gearman_server_thread_init.
  34. * @param fd File descriptor for a newly accepted connection.
  35. * @param data Application data pointer.
  36. * @return Gearman server connection pointer.
  37. */
  38. GEARMAN_API
  39. gearman_server_con_st *gearman_server_con_add(gearman_server_thread_st *thread, gearmand_con_st *dcon,
  40. gearmand_error_t *ret);
  41. /**
  42. * Free a server connection structure.
  43. */
  44. GEARMAN_API
  45. void gearman_server_con_free(gearman_server_con_st *con);
  46. /**
  47. * Get gearman connection pointer the server connection uses.
  48. */
  49. GEARMAN_API
  50. gearmand_io_st *gearman_server_con_con(gearman_server_con_st *con);
  51. /**
  52. * Get application data pointer.
  53. */
  54. GEARMAN_API
  55. gearmand_con_st *gearman_server_con_data(gearman_server_con_st *con);
  56. /**
  57. * Get client id.
  58. */
  59. GEARMAN_API
  60. const char *gearman_server_con_id(gearman_server_con_st *con);
  61. /**
  62. * Set client id.
  63. */
  64. GEARMAN_API
  65. void gearman_server_con_set_id(gearman_server_con_st *con, char *id,
  66. size_t size);
  67. /**
  68. * Free server worker struction with name for a server connection.
  69. */
  70. GEARMAN_API
  71. void gearman_server_con_free_worker(gearman_server_con_st *con,
  72. char *function_name,
  73. size_t function_name_size);
  74. /**
  75. * Free all server worker structures for a server connection.
  76. */
  77. GEARMAN_API
  78. void gearman_server_con_free_workers(gearman_server_con_st *con);
  79. /**
  80. * Add connection to the io thread list.
  81. */
  82. GEARMAN_API
  83. void gearman_server_con_io_add(gearman_server_con_st *con);
  84. /**
  85. * Remove connection from the io thread list.
  86. */
  87. GEARMAN_API
  88. void gearman_server_con_io_remove(gearman_server_con_st *con);
  89. /**
  90. * Get next connection from the io thread list.
  91. */
  92. GEARMAN_API
  93. gearman_server_con_st *
  94. gearman_server_con_io_next(gearman_server_thread_st *thread);
  95. /**
  96. * Add connection to the proc thread list.
  97. */
  98. GEARMAN_API
  99. void gearman_server_con_proc_add(gearman_server_con_st *con);
  100. /**
  101. * Remove connection from the proc thread list.
  102. */
  103. GEARMAN_API
  104. void gearman_server_con_proc_remove(gearman_server_con_st *con);
  105. /**
  106. * Get next connection from the proc thread list.
  107. */
  108. GEARMAN_API
  109. gearman_server_con_st *
  110. gearman_server_con_proc_next(gearman_server_thread_st *thread);
  111. /**
  112. * Set protocol context pointer.
  113. * Add worker timeout for a connection tied to a job
  114. */
  115. GEARMAN_INTERNAL_API
  116. void gearmand_connection_set_protocol(gearman_server_con_st *connection,
  117. void *context,
  118. gearmand_connection_protocol_context_free_fn *free_fn,
  119. gearmand_packet_pack_fn *pack,
  120. gearmand_packet_unpack_fn *unpack);
  121. /**
  122. * Set protocol context pointer.
  123. * Add worker timeout for a connection tied to a job
  124. */
  125. GEARMAN_API
  126. gearmand_error_t gearman_server_con_add_job_timeout(gearman_server_con_st *con, gearman_server_job_st *job);
  127. GEARMAN_INTERNAL_API
  128. void *gearmand_connection_protocol_context(const gearman_server_con_st *connection);
  129. /**
  130. * Delete timeout event for a server con
  131. */
  132. GEARMAN_API
  133. void gearman_server_con_delete_timeout(gearman_server_con_st *con);
  134. /** @} */
  135. #ifdef __cplusplus
  136. }
  137. #endif