-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathconnection.h
61 lines (39 loc) · 1.24 KB
/
connection.h
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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
#ifndef CONNECTION_H
#define CONNECTION_H
#include <array>
#include <memory>
#include <boost/asio.hpp>
#include <string>
#include "request_handler.h"
#include <map>
namespace http {
namespace server {
// 8192 is maximum size of a package sent on a network
static const int MAX_BUFFER_SIZE = 8192;
class connection : public std::enable_shared_from_this<connection>
{
public:
// Does not allow us to make copies of this class
// connection(const connection&) = delete;
// connection& operator=(const connection&) = delete;
explicit connection(boost::asio::ip::tcp::socket socket, std::map <std::string, RequestHandler*> handlers);
void start();
void stop();
Response get_response();
void write_response();
Request call_parser(std::string data);
RequestHandler* find_handler(Request& request);
RequestHandler::Status call_handler(RequestHandler* handler_mode);
private:
void do_read();
boost::asio::io_service io_service_;
boost::asio::ip::tcp::socket socket_;
std::array<char, MAX_BUFFER_SIZE> buffer_;
Response res;
Request req;
/// The handler used to process the incoming request.
std::map <std::string, RequestHandler*> handlers_;
};
} // namespace server
} // namespace http
#endif // HTTP_CONNECTION_HPP