io.h 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144
  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. #include <libgearman-server/struct/connection_list.h>
  47. #ifdef __cplusplus
  48. extern "C" {
  49. #endif
  50. /**
  51. * @addtogroup gearman_con Connection Declarations
  52. * @ingroup gearman_universal
  53. *
  54. * This is a low level interface for gearman connections. This is used
  55. * internally by both client and worker interfaces, so you probably want to
  56. * look there first. This is usually used to write lower level clients, workers,
  57. * proxies, or your own server.
  58. *
  59. * @{
  60. */
  61. /**
  62. * @ingroup gearman_connection
  63. */
  64. /** Initialize a connection structure. Always check the return value even if
  65. * passing in a pre-allocated structure. Some other initialization may have
  66. * failed.
  67. *
  68. * @param[in] gearman Structure previously initialized with gearman_create() or
  69. * gearman_clone().
  70. * @param[in] connection Caller allocated structure, or NULL to allocate one.
  71. * @return On success, a pointer to the (possibly allocated) structure. On
  72. * failure this will be NULL.
  73. */
  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. void gearmand_io_free(gearmand_io_st *connection);
  85. gearmand_error_t gearman_io_set_option(gearmand_io_st *connection,
  86. gearmand_connection_options_t options,
  87. bool value);
  88. /**
  89. * Set connection to an already open file descriptor.
  90. */
  91. gearmand_error_t gearman_io_set_fd(gearmand_io_st *connection, int fd);
  92. /**
  93. * Get application context pointer.
  94. */
  95. gearmand_con_st *gearman_io_context(const gearmand_io_st *connection);
  96. /**
  97. * Used by thread to send packets.
  98. */
  99. gearmand_error_t gearman_io_send(gearman_server_con_st *connection,
  100. const struct gearmand_packet_st *packet, bool flush);
  101. /**
  102. * Used by thread to recv packets.
  103. */
  104. gearmand_error_t gearman_io_recv(gearman_server_con_st *con, bool recv_data);
  105. /**
  106. * Set events to be watched for a connection.
  107. */
  108. gearmand_error_t gearmand_io_set_events(gearman_server_con_st *connection, short events);
  109. /**
  110. * Set events that are ready for a connection. This is used with the external
  111. * event callbacks.
  112. */
  113. gearmand_error_t gearmand_io_set_revents(gearman_server_con_st *connection, short revents);
  114. void gearmand_sockfd_close(int&);
  115. void gearmand_pipe_close(int&);
  116. gearmand_error_t gearmand_sockfd_nonblock(const int&);
  117. /** @} */
  118. #ifdef __cplusplus
  119. }
  120. #endif