ws_conn.h 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  1. /*
  2. * $Id$
  3. *
  4. * Copyright (C) 2012-2013 Crocodile RCS Ltd
  5. *
  6. * This file is part of Kamailio, a free SIP server.
  7. *
  8. * Kamailio is free software; you can redistribute it and/or modify
  9. * it under the terms of the GNU General Public License as published by
  10. * the Free Software Foundation; either version 2 of the License, or
  11. * (at your option) any later version
  12. *
  13. * Kamailio is distributed in the hope that it will be useful,
  14. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  16. * GNU General Public License for more details.
  17. *
  18. * You should have received a copy of the GNU General Public License
  19. * along with this program; if not, write to the Free Software
  20. * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  21. *
  22. * Exception: permission to copy, modify, propagate, and distribute a work
  23. * formed by combining OpenSSL toolkit software and the code in this file,
  24. * such as linking with software components and libraries released under
  25. * OpenSSL project license.
  26. *
  27. */
  28. #ifndef _WS_CONN_H
  29. #define _WS_CONN_H
  30. #include "../../atomic_ops.h"
  31. #include "../../lib/kcore/kstats_wrapper.h"
  32. #include "../../lib/kmi/tree.h"
  33. typedef enum
  34. {
  35. WS_S_CONNECTING = 0, /* Never used - included for completeness */
  36. WS_S_OPEN,
  37. WS_S_CLOSING,
  38. WS_S_CLOSED /* Never used - included for completeness */
  39. } ws_conn_state_t;
  40. typedef struct ws_connection
  41. {
  42. ws_conn_state_t state;
  43. int awaiting_pong;
  44. int last_used;
  45. struct ws_connection *used_prev;
  46. struct ws_connection *used_next;
  47. int id; /* id and id_hash are identical to the values */
  48. unsigned id_hash; /* for the corresponding TCP/TLS connection */
  49. struct ws_connection *id_prev;
  50. struct ws_connection *id_next;
  51. struct receive_info rcv;
  52. unsigned int sub_protocol;
  53. atomic_t refcnt;
  54. int run_event;
  55. } ws_connection_t;
  56. typedef struct
  57. {
  58. ws_connection_t *head;
  59. ws_connection_t *tail;
  60. } ws_connection_used_list_t;
  61. typedef enum
  62. {
  63. WSCONN_EVENTROUTE_NO = 0,
  64. WSCONN_EVENTROUTE_YES
  65. } ws_conn_eventroute_t;
  66. extern ws_connection_used_list_t *wsconn_used_list;
  67. extern char *wsconn_state_str[];
  68. extern stat_var *ws_current_connections;
  69. extern stat_var *ws_max_concurrent_connections;
  70. extern stat_var *ws_sip_current_connections;
  71. extern stat_var *ws_sip_max_concurrent_connections;
  72. extern stat_var *ws_msrp_current_connections;
  73. extern stat_var *ws_msrp_max_concurrent_connections;
  74. int wsconn_init(void);
  75. void wsconn_destroy(void);
  76. int wsconn_add(struct receive_info rcv, unsigned int sub_protocol);
  77. int wsconn_rm(ws_connection_t *wsc, ws_conn_eventroute_t run_event_route);
  78. int wsconn_update(ws_connection_t *wsc);
  79. void wsconn_close_now(ws_connection_t *wsc);
  80. ws_connection_t *wsconn_get(int id);
  81. int wsconn_put(ws_connection_t *wsc);
  82. ws_connection_t **wsconn_get_list(void);
  83. int wsconn_put_list(ws_connection_t **list);
  84. struct mi_root *ws_mi_dump(struct mi_root *cmd, void *param);
  85. #endif /* _WS_CONN_H */