io.h 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151
  1. /* vim:expandtab:shiftwidth=2:tabstop=2:smarttab:
  2. *
  3. * Gearmand client and server library.
  4. *
  5. * Copyright (C) 2011-2012 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. /**
  39. * @file
  40. * @brief Connection Declarations
  41. */
  42. #pragma once
  43. #include <sys/types.h>
  44. #include <sys/socket.h>
  45. #include <netdb.h>
  46. #ifdef __cplusplus
  47. extern "C" {
  48. #endif
  49. /**
  50. * @addtogroup gearman_con Connection Declarations
  51. * @ingroup gearman_universal
  52. *
  53. * This is a low level interface for gearman connections. This is used
  54. * internally by both client and worker interfaces, so you probably want to
  55. * look there first. This is usually used to write lower level clients, workers,
  56. * proxies, or your own server.
  57. *
  58. * @{
  59. */
  60. /**
  61. * @ingroup gearman_connection
  62. */
  63. /** Initialize a connection structure. Always check the return value even if
  64. * passing in a pre-allocated structure. Some other initialization may have
  65. * failed.
  66. *
  67. * @param[in] gearman Structure previously initialized with gearman_create() or
  68. * gearman_clone().
  69. * @param[in] connection Caller allocated structure, or NULL to allocate one.
  70. * @return On success, a pointer to the (possibly allocated) structure. On
  71. * failure this will be NULL.
  72. */
  73. GEARMAN_INTERNAL_API
  74. void gearmand_connection_init(gearmand_connection_list_st *gearman,
  75. gearmand_io_st *connection,
  76. struct gearmand_con_st *dcon,
  77. gearmand_connection_options_t *options);
  78. /**
  79. * Free a connection structure.
  80. *
  81. * @param[in] connection Structure previously initialized with gearmand_connection_init(),
  82. * gearmand_connection_init_args(), or gearman_connection_clone().
  83. */
  84. GEARMAN_INTERNAL_API
  85. void gearmand_io_free(gearmand_io_st *connection);
  86. GEARMAN_INTERNAL_API
  87. gearmand_error_t gearman_io_set_option(gearmand_io_st *connection,
  88. gearmand_connection_options_t options,
  89. bool value);
  90. /**
  91. * Set connection to an already open file descriptor.
  92. */
  93. GEARMAN_INTERNAL_API
  94. gearmand_error_t gearman_io_set_fd(gearmand_io_st *connection, int fd);
  95. /**
  96. * Get application context pointer.
  97. */
  98. GEARMAN_INTERNAL_API
  99. gearmand_con_st *gearman_io_context(const gearmand_io_st *connection);
  100. /**
  101. * Used by thread to send packets.
  102. */
  103. GEARMAN_INTERNAL_API
  104. gearmand_error_t gearman_io_send(gearman_server_con_st *connection,
  105. const gearmand_packet_st *packet, bool flush);
  106. /**
  107. * Used by thread to recv packets.
  108. */
  109. GEARMAN_INTERNAL_API
  110. gearmand_error_t gearman_io_recv(gearman_server_con_st *con, bool recv_data);
  111. /**
  112. * Set events to be watched for a connection.
  113. */
  114. GEARMAN_INTERNAL_API
  115. gearmand_error_t gearmand_io_set_events(gearman_server_con_st *connection, short events);
  116. /**
  117. * Set events that are ready for a connection. This is used with the external
  118. * event callbacks.
  119. */
  120. GEARMAN_INTERNAL_API
  121. gearmand_error_t gearmand_io_set_revents(gearman_server_con_st *connection, short revents);
  122. GEARMAN_INTERNAL_API
  123. void gearmand_sockfd_close(int sockfd);
  124. GEARMAN_INTERNAL_API
  125. void gearmand_pipe_close(int sockfd);
  126. /** @} */
  127. #ifdef __cplusplus
  128. }
  129. #endif