io.h 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121
  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 <sys/types.h>
  14. #include <sys/socket.h>
  15. #include <netdb.h>
  16. #ifdef __cplusplus
  17. extern "C" {
  18. #endif
  19. /**
  20. * @addtogroup gearman_con Connection Declarations
  21. * @ingroup gearman_universal
  22. *
  23. * This is a low level interface for gearman connections. This is used
  24. * internally by both client and worker interfaces, so you probably want to
  25. * look there first. This is usually used to write lower level clients, workers,
  26. * proxies, or your own server.
  27. *
  28. * @{
  29. */
  30. /**
  31. * @ingroup gearman_connection
  32. */
  33. /** Initialize a connection structure. Always check the return value even if
  34. * passing in a pre-allocated structure. Some other initialization may have
  35. * failed.
  36. *
  37. * @param[in] gearman Structure previously initialized with gearman_create() or
  38. * gearman_clone().
  39. * @param[in] connection Caller allocated structure, or NULL to allocate one.
  40. * @return On success, a pointer to the (possibly allocated) structure. On
  41. * failure this will be NULL.
  42. */
  43. GEARMAN_INTERNAL_API
  44. void gearmand_connection_init(gearmand_connection_list_st *gearman,
  45. gearmand_io_st *connection,
  46. struct gearmand_con_st *dcon,
  47. gearmand_connection_options_t *options);
  48. /**
  49. * Free a connection structure.
  50. *
  51. * @param[in] connection Structure previously initialized with gearmand_connection_init(),
  52. * gearmand_connection_init_args(), or gearman_connection_clone().
  53. */
  54. GEARMAN_INTERNAL_API
  55. void gearmand_io_free(gearmand_io_st *connection);
  56. GEARMAN_INTERNAL_API
  57. gearmand_error_t gearman_io_set_option(gearmand_io_st *connection,
  58. gearmand_connection_options_t options,
  59. bool value);
  60. /**
  61. * Set connection to an already open file descriptor.
  62. */
  63. GEARMAN_INTERNAL_API
  64. gearmand_error_t gearman_io_set_fd(gearmand_io_st *connection, int fd);
  65. /**
  66. * Get application context pointer.
  67. */
  68. GEARMAN_INTERNAL_API
  69. gearmand_con_st *gearman_io_context(const gearmand_io_st *connection);
  70. /**
  71. * Used by thread to send packets.
  72. */
  73. GEARMAN_INTERNAL_API
  74. gearmand_error_t gearman_io_send(gearman_server_con_st *connection,
  75. const gearmand_packet_st *packet, bool flush);
  76. /**
  77. * Used by thread to recv packets.
  78. */
  79. GEARMAN_INTERNAL_API
  80. gearmand_error_t gearman_io_recv(gearman_server_con_st *con, bool recv_data);
  81. /**
  82. * Set events to be watched for a connection.
  83. */
  84. GEARMAN_INTERNAL_API
  85. gearmand_error_t gearmand_io_set_events(gearman_server_con_st *connection, short events);
  86. /**
  87. * Set events that are ready for a connection. This is used with the external
  88. * event callbacks.
  89. */
  90. GEARMAN_INTERNAL_API
  91. gearmand_error_t gearmand_io_set_revents(gearman_server_con_st *connection, short revents);
  92. GEARMAN_INTERNAL_API
  93. void gearmand_sockfd_close(int sockfd);
  94. GEARMAN_INTERNAL_API
  95. void gearmand_pipe_close(int sockfd);
  96. /** @} */
  97. #ifdef __cplusplus
  98. }
  99. #endif