Apollo  6.0
Open source self driving car software
client.h
Go to the documentation of this file.
1 
7 #pragma once
8 
9 #include <cstdint>
10 #include <string>
11 #include <vector>
12 
13 #include "boost/asio.hpp"
14 
15 class Clients;
16 class Node;
17 
18 class Client : public std::enable_shared_from_this<Client> {
19  public:
20  Client(Node* node, Clients* clients, boost::asio::ip::tcp::socket socket);
21  ~Client();
22 
23  void start();
24  void stop();
25 
26  void publish(const std::string& channel, const std::string& msg);
27 
28  private:
29  Node& node;
30  Clients& clients;
31 
32  boost::asio::ip::tcp::socket socket;
33 
34  uint8_t temp[1024 * 1024];
35  std::vector<uint8_t> buffer;
36  std::vector<uint8_t> writing;
37  std::vector<uint8_t> pending;
38  std::mutex publish_mutex;
39  const uint MAX_PENDING_SIZE = 1073741824; // 1GB
40 
41  void handle_read(const boost::system::error_code& ec, std::size_t length);
42  void handle_write(const boost::system::error_code& ec);
43 
44  void handle_register_desc();
45  void handle_add_writer();
46  void handle_add_reader();
47  void handle_publish();
48 
49  uint32_t get32le(size_t offset) const;
50 };
Definition: clients.h:16
Definition: node.h:31
void start()
void stop()
void publish(const std::string &channel, const std::string &msg)
Client(Node *node, Clients *clients, boost::asio::ip::tcp::socket socket)
Definition: client.h:18