-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathconnection.h
43 lines (33 loc) · 935 Bytes
/
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
#ifndef CONNECTION_H
#define CONNECTION_H
#include <boost/asio.hpp>
#include <array>
#include <memory>
#include "Request.h"
#include "Response.h"
enum { max_length = 8192 };
namespace Team15 {
namespace server {
class server;
class connection
: public std::enable_shared_from_this<connection>
{
public:
explicit connection(boost::asio::ip::tcp::socket socket,server* server);
void start();
void stop();
//for testing purposes
void setBuffer(std::string& str);
private:
void start_reading();
void read_handler(const boost::system::error_code& ec,std::size_t bytes_transferred);
void start_writing(std::size_t bytes_transferred);
void write_handler(const boost::system::error_code& ec,std::size_t bytes_transferred);
boost::asio::ip::tcp::socket socket_;
std::array<char,max_length> buffer_;
server* server_;
};
typedef std::shared_ptr<connection> connection_ptr;
}
}
#endif // CONNECTION_H