port.h 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  1. /* vim:expandtab:shiftwidth=2:tabstop=2:smarttab:
  2. *
  3. * Gearmand client and server library.
  4. *
  5. * Copyright (C) 2011 Data Differential, http://datadifferential.com/
  6. * All rights reserved.
  7. *
  8. * Redistribution and use in source and binary forms, with or without
  9. * modification, are permitted provided that the following conditions are
  10. * met:
  11. *
  12. * * Redistributions of source code must retain the above copyright
  13. * notice, this list of conditions and the following disclaimer.
  14. *
  15. * * Redistributions in binary form must reproduce the above
  16. * copyright notice, this list of conditions and the following disclaimer
  17. * in the documentation and/or other materials provided with the
  18. * distribution.
  19. *
  20. * * The names of its contributors may not be used to endorse or
  21. * promote products derived from this software without specific prior
  22. * written permission.
  23. *
  24. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
  25. * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
  26. * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
  27. * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
  28. * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
  29. * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
  30. * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
  31. * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
  32. * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  33. * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
  34. * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  35. *
  36. */
  37. #pragma once
  38. #include <netdb.h>
  39. struct gearmand_port_st
  40. {
  41. char port[NI_MAXSERV];
  42. uint32_t listen_count;
  43. private:
  44. gearmand_connection_add_fn *_add_fn;
  45. gearmand_connection_remove_fn *_remove_fn;
  46. public:
  47. int *listen_fd;
  48. struct event *listen_event;
  49. gearmand_port_st() :
  50. listen_count{0},
  51. _add_fn{nullptr},
  52. _remove_fn{nullptr},
  53. listen_fd{nullptr},
  54. listen_event{nullptr}
  55. {
  56. port[0]= 0;
  57. }
  58. ~gearmand_port_st()
  59. {
  60. if (listen_fd)
  61. {
  62. free(listen_fd);
  63. }
  64. if (listen_event)
  65. {
  66. free(listen_event);
  67. }
  68. }
  69. gearmand_error_t add_fn(gearman_server_con_st* con)
  70. {
  71. assert(_add_fn);
  72. return (*_add_fn)(con);
  73. }
  74. gearmand_error_t remove_fn(gearman_server_con_st* con)
  75. {
  76. assert(_remove_fn);
  77. return (*_remove_fn)(con);
  78. }
  79. void add_fn(gearmand_connection_add_fn* add_fn_)
  80. {
  81. _add_fn= add_fn_;
  82. }
  83. void remove_fn(gearmand_connection_remove_fn* remove_fn_)
  84. {
  85. _remove_fn= remove_fn_;
  86. }
  87. };