ws_conn.h 2.9 KB

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