11#ifndef PUSH_SOCKET_H
22#define PUSH_SOCKET_H
33
4- #ifdef _WIN32
5- #define NOMINMAX // 防止 Windows 定义的 min/max 宏干扰
6- #endif
7-
8- #include < memory>
9- #include < string>
104#include " boost/asio.hpp"
11- #include " boost/asio/io_service.hpp"
12- #include " boost/asio/ip/tcp.hpp"
135#include " boost/asio/ssl.hpp"
146#include " boost/bind.hpp"
157#include " boost/pool/pool.hpp"
16- #include < boost/optional.hpp>
17- # include " cpprest/details/basic_types.h "
8+ #include " boost/optional.hpp"
9+
1810#include " tigerapi/client_config.h"
1911#include " push_frame_serialize.h"
20-
2112#include " openapi_pb/pb_source/Request.pb.h"
2213#include " openapi_pb/pb_source/Response.pb.h"
2314
@@ -27,7 +18,6 @@ namespace TIGER_API
2718 {
2819 CONNECTING, // 正在连接
2920 CONNECTED, // 已连接
30- DISCONNECTING, // 正在断开
3121 DISCONNECTED // 已断开
3222 };
3323
@@ -54,7 +44,7 @@ namespace TIGER_API
5444 void connect ();
5545 void disconnect ();
5646 bool send_message (const std::string& msg);
57- uint32_t get_next_id ();
47+ unsigned int get_next_id ();
5848 private:
5949 void init_socket ();
6050 bool verify_certificate (bool preverified,
@@ -64,20 +54,21 @@ namespace TIGER_API
6454 void start_keep_alive ();
6555 void send_heart_beat ();
6656 void auto_reconnect ();
57+ void cancel_reconnect_timer ();
6758
6859 void handle_connect (const boost::system::error_code& error,
6960 boost::asio::ip::tcp::resolver::iterator endpoint_iterator);
7061 void handle_handshake (const boost::system::error_code& error);
7162 void handle_write (const boost::system::error_code& error,
7263 size_t bytes_transferred,
73- unsigned int frame_len);
64+ size_t frame_len);
7465 void handle_read_head (const boost::system::error_code& error,
7566 size_t bytes_transferred);
7667 void handle_read_body (const boost::system::error_code& error,
7768 size_t bytes_transferred,
7869 char * recv_buff,
7970 int page_num,
80- unsigned int frame_len);
71+ size_t frame_len);
8172 void handle_timer (const boost::system::error_code& error);
8273
8374 void read_head ();
@@ -102,17 +93,17 @@ namespace TIGER_API
10293 std::shared_ptr<boost::asio::deadline_timer> reconnect_timer_;
10394 std::atomic<SocketState> socket_state_ = SocketState::DISCONNECTED;
10495
105- std::atomic<uint32_t > id_counter_ = 0 ;
96+ std::atomic<unsigned int > id_counter_ = 0 ;
10697
10798 char head_buff_[1024 ];
10899 boost::shared_ptr<boost::pool<>> recv_buff_pool_;
109100 TIGER_API::PushFrameDecoder frame_decoder_;
110101 private:
111102 std::time_t last_send_heart_beat_time_ = 0 ;
112103 std::time_t last_io_time_ = 0 ;
113- int reconnect_interval_ = 10 * 1000 ; // 单位:ms
114- int send_interval_ = 10 * 1000 ; // 单位:ms
115- int recv_interval_ = 10 * 1000 ; // 单位:ms
104+ int reconnect_interval_ = 10 * 1000 ; // 单位:ms
105+ int send_interval_ = 10 * 1000 ; // 单位:ms
106+ int recv_interval_ = 10 * 1000 ; // 单位:ms
116107 };
117108}
118109#endif // PUSH_SOCKET_H
0 commit comments