gearmand_con.h 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  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. #ifndef __GEARMAND_CON_H__
  13. #define __GEARMAND_CON_H__
  14. #include <sys/types.h>
  15. #include <sys/socket.h>
  16. #include <netdb.h>
  17. #ifdef __cplusplus
  18. extern "C" {
  19. #endif
  20. /**
  21. * @addtogroup gearmand_con Connection Declarations
  22. * @ingroup gearmand
  23. *
  24. * Connection handling for gearmand.
  25. *
  26. * @{
  27. */
  28. struct gearmand_con_st
  29. {
  30. short last_events;
  31. int fd;
  32. gearmand_thread_st *thread;
  33. gearmand_con_st *next;
  34. gearmand_con_st *prev;
  35. gearman_server_con_st *server_con;
  36. gearmand_connection_add_fn *add_fn;
  37. struct event event;
  38. char host[NI_MAXHOST];
  39. char port[NI_MAXSERV];
  40. };
  41. /**
  42. * Create a new gearmand connection.
  43. * @param gearmand Server instance structure previously initialized with
  44. * gearmand_create.
  45. * @param fd File descriptor of new connection.
  46. * @param host Host of peer connection.
  47. * @param port Port of peer connection.
  48. * @param add_fn Optional callback to use when adding the connection to an
  49. I/O thread.
  50. * @return Pointer to an allocated gearmand structure.
  51. */
  52. GEARMAN_API
  53. gearmand_error_t gearmand_con_create(gearmand_st *gearmand, int fd,
  54. const char *host, const char *port,
  55. gearmand_connection_add_fn *add_fn);
  56. /**
  57. * Free resources used by a connection.
  58. * @param dcon Connection previously initialized with gearmand_con_create.
  59. */
  60. GEARMAN_API
  61. void gearmand_con_free(gearmand_con_st *dcon);
  62. /**
  63. * Check connection queue for a thread.
  64. */
  65. GEARMAN_API
  66. void gearmand_con_check_queue(gearmand_thread_st *thread);
  67. /**
  68. * Callback function used for setting events in libevent.
  69. */
  70. GEARMAN_API
  71. gearmand_error_t gearmand_connection_watch(gearmand_io_st *con, short events,
  72. void *context);
  73. /** @} */
  74. #ifdef __cplusplus
  75. }
  76. #endif
  77. #endif /* __GEARMAND_CON_H__ */