asio_https.hpp
1 #ifndef NOOS_CLOUD_ASIO_HTTPS
2 #define NOOS_CLOUD_ASIO_HTTPS
3 /*
4  * LICENSE HERE
5  */
6 #include "includes.ihh"
7 #include <boost/asio.hpp>
8 #include <boost/asio/ssl.hpp>
9 #include <noos/cloud/asio/asio_handler.hpp>
10 namespace noos {
12 namespace cloud {
23 class asio_https
24 : public asio_handler<tls_socket, asio_https>
25 {
26 public:
35  asio_https(
36  std::function<void(std::string)> cloud_callback,
37  std::function<void(error_code error)> error_callback,
38  boost::asio::io_service & io_service,
39  const bool keep_alive,
40  boost::asio::streambuf & request
41  );
42 
50  void begin(
51  boost::asio::ip::tcp::resolver::query & query,
52  boost::asio::ip::tcp::resolver & resolver,
53  unsigned int timeout
54  );
55 
62  void send(
63  boost::asio::ip::tcp::resolver::query & query,
64  boost::asio::ip::tcp::resolver & resolver,
65  unsigned int timeout,
66  boost::asio::streambuf & request
67  );
68 
70  void shutdown(const boost::system::error_code);
71 
73  void stop_timeout();
74 
76  bool is_connected() const;
77 
78 private:
80 
82  bool verify_certificate(bool preverified, boost::asio::ssl::verify_context& ctx);
83 
85  void connect(const boost::system::error_code err);
86 
88  void handshake(const boost::system::error_code err);
89 
91  void time_check(const boost::system::error_code & ec);
92 
93  std::function<void(boost::system::error_code err)> error_;
94  std::function<void(std::string)> callback_;
95  boost::asio::ssl::context ctx_;
96  std::shared_ptr<tls_socket> socket_;
97  boost::asio::streambuf & request_;
98  std::shared_ptr<boost::asio::deadline_timer> deadline_;
99  std::atomic<bool> connected_ = { false };
100 };
101 }
102 }
103 #endif
void send(boost::asio::ip::tcp::resolver::query &query, boost::asio::ip::tcp::resolver &resolver, unsigned int timeout, boost::asio::streambuf &request)
send data in an existing connection
ASIO socket controller of boost asio socket type T.
Definition: asio_handler.hpp:27
Definition: asio_handler.hpp:14
void shutdown(const boost::system::error_code)
shutdown handler
asio_https(std::function< void(std::string)> cloud_callback, std::function< void(error_code error)> error_callback, boost::asio::io_service &io_service, const bool keep_alive, boost::asio::streambuf &request)
constructor
bool is_connected() const
void stop_timeout()
stop timeout timer
void begin(boost::asio::ip::tcp::resolver::query &query, boost::asio::ip::tcp::resolver &resolver, unsigned int timeout)
begin connection
ASIO socket controller for TLS (encrypred) cloud service calls.
Definition: asio_https.hpp:23