sio_client.cpp 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128
  1. //
  2. // sio_client.h
  3. //
  4. // Created by Melo Yao on 3/25/15.
  5. //
  6. #include "sio_client.h"
  7. #include "internal/sio_client_impl.h"
  8. using namespace websocketpp;
  9. using boost::posix_time::milliseconds;
  10. using std::stringstream;
  11. namespace sio
  12. {
  13. client::client():
  14. m_impl(new client_impl())
  15. {
  16. }
  17. client::~client()
  18. {
  19. delete m_impl;
  20. }
  21. void client::set_open_listener(con_listener const& l)
  22. {
  23. m_impl->set_open_listener(l);
  24. }
  25. void client::set_fail_listener(con_listener const& l)
  26. {
  27. m_impl->set_fail_listener(l);
  28. }
  29. void client::set_close_listener(close_listener const& l)
  30. {
  31. m_impl->set_close_listener(l);
  32. }
  33. void client::set_socket_open_listener(socket_listener const& l)
  34. {
  35. m_impl->set_socket_open_listener(l);
  36. }
  37. void client::set_reconnect_listener(reconnect_listener const& l)
  38. {
  39. m_impl->set_reconnect_listener(l);
  40. }
  41. void client::set_reconnecting_listener(con_listener const& l)
  42. {
  43. m_impl->set_reconnecting_listener(l);
  44. }
  45. void client::set_socket_close_listener(socket_listener const& l)
  46. {
  47. m_impl->set_socket_close_listener(l);
  48. }
  49. void client::clear_con_listeners()
  50. {
  51. m_impl->clear_con_listeners();
  52. }
  53. void client::clear_socket_listeners()
  54. {
  55. m_impl->clear_socket_listeners();
  56. }
  57. void client::connect(const std::string& uri)
  58. {
  59. m_impl->connect(uri, {}, {});
  60. }
  61. void client::connect(const std::string& uri, const std::map<string,string>& query)
  62. {
  63. m_impl->connect(uri, query, {});
  64. }
  65. void client::connect(const std::string& uri, const std::map<std::string,std::string>& query,
  66. const std::map<std::string,std::string>& http_extra_headers)
  67. {
  68. m_impl->connect(uri, query, http_extra_headers);
  69. }
  70. socket::ptr const& client::socket(const std::string& nsp)
  71. {
  72. return m_impl->socket(nsp);
  73. }
  74. // Closes the connection
  75. void client::close()
  76. {
  77. m_impl->close();
  78. }
  79. void client::sync_close()
  80. {
  81. m_impl->sync_close();
  82. }
  83. bool client::opened() const
  84. {
  85. return m_impl->opened();
  86. }
  87. std::string const& client::get_sessionid() const
  88. {
  89. return m_impl->get_sessionid();
  90. }
  91. void client::set_reconnect_attempts(int attempts)
  92. {
  93. m_impl->set_reconnect_attempts(attempts);
  94. }
  95. void client::set_reconnect_delay(unsigned millis)
  96. {
  97. m_impl->set_reconnect_delay(millis);
  98. }
  99. void client::set_reconnect_delay_max(unsigned millis)
  100. {
  101. m_impl->set_reconnect_delay_max(millis);
  102. }
  103. }