asio_http.hpp
1 #ifndef NOOS_CLOUD_ASIO_HTTP
2 #define NOOS_CLOUD_ASIO_HTTP
3 /*
4  * LICENSE HERE
5  */
6 #include "includes.ihh"
7 #include <boost/asio.hpp>
8 #include <noos/cloud/asio/asio_handler.hpp>
9 namespace noos {
11 namespace cloud {
22 class asio_http
23 : public asio_handler<http_socket, asio_http>
24 {
25 public:
33  asio_http(
34  std::function<void(std::string)> cloud_callback,
35  std::function<void(error_code)> error_callback,
36  boost::asio::io_service & io_service,
37  const bool keep_alive,
38  boost::asio::streambuf & request
39  );
40 
47  void begin(
48  boost::asio::ip::tcp::resolver::query & query,
49  boost::asio::ip::tcp::resolver & resolver,
50  unsigned int timeout
51  );
52 
59  void send(
60  boost::asio::ip::tcp::resolver::query & query,
61  boost::asio::ip::tcp::resolver & resolver,
62  unsigned int timeout,
63  boost::asio::streambuf & request
64  );
65 
67  void shutdown(boost::system::error_code);
68 
70  void stop_timeout();
71 
73  bool is_connected() const;
74 
75 private:
77 
78  // resolve endpoint/hostname
79  void resolve(
80  boost::system::error_code err,
81  boost::asio::ip::tcp::resolver::iterator endpoint_iterator
82  );
83 
84  // begin connection
85  void connect(
86  const boost::system::error_code err,
87  boost::asio::ip::tcp::resolver::iterator endpoint_iterator
88  );
89 
90  // check if we have timed out
91  void time_check(const boost::system::error_code & ec);
92 
93  // members
94  std::function<void(boost::system::error_code)> error_;
95  std::function<void(std::string)> callback_;
96  std::shared_ptr<http_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
ASIO socket controller asynchronous http websockets used for cloud service calls. ...
Definition: asio_http.hpp:22
void begin(boost::asio::ip::tcp::resolver::query &query, boost::asio::ip::tcp::resolver &resolver, unsigned int timeout)
begin connection
ASIO socket controller of boost asio socket type T.
Definition: asio_handler.hpp:27
Definition: asio_handler.hpp:14
asio_http(std::function< void(std::string)> cloud_callback, std::function< void(error_code)> error_callback, boost::asio::io_service &io_service, const bool keep_alive, boost::asio::streambuf &request)
constructor
void shutdown(boost::system::error_code)
shutdown connection
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
bool is_connected() const
void stop_timeout()
stop timeout timer