-
Notifications
You must be signed in to change notification settings - Fork 233
Expand file tree
/
Copy pathccapi_http_connection.h
More file actions
39 lines (29 loc) · 1.12 KB
/
ccapi_http_connection.h
File metadata and controls
39 lines (29 loc) · 1.12 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
#pragma once
#include <string>
#include "ccapi_cpp/ccapi_logger.h"
namespace beast = boost::beast;
namespace ccapi {
class HttpConnection {
/**
* This class represents a TCP socket connection for the REST API.
*/
public:
HttpConnection(const HttpConnection&) = delete;
HttpConnection& operator=(const HttpConnection&) = delete;
HttpConnection(std::string host, std::string port, std::shared_ptr<beast::ssl_stream<beast::tcp_stream>> streamPtr)
: host(host), port(port), streamPtr(streamPtr) {}
std::string toString() const {
std::ostringstream oss;
oss << streamPtr;
std::string output = "HttpConnection [host = " + host + ", port = " + port + ", streamPtr = " + oss.str() +
", lastReceiveDataTp = " + UtilTime::getISOTimestamp(lastReceiveDataTp) + "]";
return output;
}
void clearBuffer() { this->buffer.consume(this->buffer.size()); }
std::string host;
std::string port;
std::shared_ptr<beast::ssl_stream<beast::tcp_stream>> streamPtr{nullptr};
TimePoint lastReceiveDataTp{std::chrono::seconds{0}};
boost::beast::flat_buffer buffer;
};
} /* namespace ccapi */