src/​examples/​cpp03/​http/​server/​connection.​hpp | src/​examples/​cpp11/​http/​server/​connection.​hpp
--- | ---
⋮ | ⋮
1 | /​/​ | 1 | /​/​
2 | /​/​·​connection.​hpp | 2 | /​/​·​connection.​hpp
3 | /​/​·​~~~~~~~~~~~~~~ | 3 | /​/​·​~~~~~~~~~~~~~~
4 | /​/​ | 4 | /​/​
5 | /​/​·​Copyright·​(c)​·​2003-​2020·​Christopher·​M.​·​Kohlhoff·​(chris·​at·​kohlhoff·​dot·​com)​ | 5 | /​/​·​Copyright·​(c)​·​2003-​2020·​Christopher·​M.​·​Kohlhoff·​(chris·​at·​kohlhoff·​dot·​com)​
6 | /​/​ | 6 | /​/​
7 | /​/​·​Distributed·​under·​the·​Boost·​Software·​License,​·​Version·​1.​0.​·​(See·​accompanying | 7 | /​/​·​Distributed·​under·​the·​Boost·​Software·​License,​·​Version·​1.​0.​·​(See·​accompanying
8 | /​/​·​file·​LICENSE_1_0.​txt·​or·​copy·​at·​http:​/​/​www.​boost.​org/​LICENSE_1_0.​txt)​ | 8 | /​/​·​file·​LICENSE_1_0.​txt·​or·​copy·​at·​http:​/​/​www.​boost.​org/​LICENSE_1_0.​txt)​
9 | /​/​ | 9 | /​/​
10 |  | 10 |
11 | #ifndef·​HTTP_CONNECTION_HPP | 11 | #ifndef·​HTTP_CONNECTION_HPP
12 | #define·​HTTP_CONNECTION_HPP | 12 | #define·​HTTP_CONNECTION_HPP
13 |  | 13 |
| 14 | #include·​<array>
| 15 | #include·​<memory>
14 | #include·​<asio.​hpp> | 16 | #include·​<asio.​hpp>
15 | #include·​<boost/​array.​hpp> |
16 | #include·​<boost/​noncopyable.​hpp> |
17 | #include·​<boost/​shared_ptr.​hpp> |
18 | #include·​<boost/​enable_shared_from_th​is.​hpp> |
19 | #include·​"reply.​hpp" | 17 | #include·​"reply.​hpp"
20 | #include·​"request.​hpp" | 18 | #include·​"request.​hpp"
21 | #include·​"request_handler.​hpp" | 19 | #include·​"request_handler.​hpp"
22 | #include·​"request_parser.​hpp" | 20 | #include·​"request_parser.​hpp"
23 |  | 21 |
24 | namespace·​http·​{ | 22 | namespace·​http·​{
25 | namespace·​server·​{ | 23 | namespace·​server·​{
26 |  | 24 |
27 | class·​connection_manager;​ | 25 | class·​connection_manager;​
28 |  | 26 |
29 | /​/​/​·​Represents·​a·​single·​connection·​from·​a·​client.​ | 27 | /​/​/​·​Represents·​a·​single·​connection·​from·​a·​client.​
30 | class·​connection | 28 | class·​connection
31 | ·​·​:​·​public·​b o ost:​:​enable_shared_from_th​is<connection>,​ | 29 | ·​·​:​·​public·​std:​:​enable_shared_from_th​is<connection>
32 | ·​·​·​·​p r i v a t e·​b o o s t:​:​n o n c o p y a b l e |
33 | { | 30 | {
34 | public:​ | 31 | public:​
35 | ·​·​/​/​/​·​C o n s t r uct·​a·​connection·​w i t h·​t h e·​g i ven·​i o_c o ntex t.​ | 32 | ·​·​c o n n e c t i o n(co n s t·​connection&)​·​=·​del ete;​
36 | ·​·​e x p l icit·​c o n nec t ion(a s io:​:​i o_context&·​i o_c o ntex t,​ | 33 | ·​·​c o n n ectio n&·​o per a tor=(con s t·​connecti o n&)​·​=·​d e l ete;​
37 | ·​·​·​·​·​·​c o n n e c t i o n_m a n a g e r&·​m a n a g e r,​·​r e q u e s t_h a n d l e r&·​h a n d l e r)​;​ |
38 |  | 34 |
39 | ·​·​/​/​/​·​G e t·​th e·​s ock et·​as soc i ate d·​with·​the·​c onn e c t i o n.​ | 35 | ·​·​/​/​/​·​C o n str uct·​a·​con n e cti o n·​with·​the·​g i v en·​s o c k e t.​
40 | ·​·​asio:​:​ip:​:​tcp:​:​socket&·​socket()​;​ | 36 | ·​·​e x p l i c i t·​c o n n e c t i o n(asio:​:​ip:​:​tcp:​:​socket·​socket,​
| 37 | ·​·​·​·​·​·​connection_manager&·​manager,​·​request_handler&·​handler)​;​
41 |  | 38 |
42 | ·​·​/​/​/​·​Start·​the·​first·​asynchronous·​operation·​for·​the·​connection.​ | 39 | ·​·​/​/​/​·​Start·​the·​first·​asynchronous·​operation·​for·​the·​connection.​
43 | ·​·​void·​start()​;​ | 40 | ·​·​void·​start()​;​
44 |  | 41 |
45 | ·​·​/​/​/​·​Stop·​all·​asynchronous·​operations·​associated·​with·​the·​connection.​ | 42 | ·​·​/​/​/​·​Stop·​all·​asynchronous·​operations·​associated·​with·​the·​connection.​
46 | ·​·​void·​stop()​;​ | 43 | ·​·​void·​stop()​;​
47 |  | 44 |
48 | private:​ | 45 | private:​
49 | ·​·​/​/​/​·​H a n d l e·​c o m p l e t ion·​of·​a·​read·​operation.​ | 46 | ·​·​/​/​/​·​P e r f o r m·​a n·​a s y n c h ronou s·​read·​operation.​
50 | ·​·​void·​h a ndl e_read(c o n s t·​a s i o:​:​e r r o r_c o d e&·​e,​ | 47 | ·​·​void·​do_read()​;​
51 | ·​·​·​·​·​·​s t d:​:​s i z e_t·​b y t e s_t r a n s f e r r e d)​;​ |
52 |  | 48 |
53 | ·​·​/​/​/​·​H a n d l e·​c o m p l e t ion·​of·​a·​write·​operation.​ | 49 | ·​·​/​/​/​·​P e r f o r m·​a n·​a s y n c h ronou s·​write·​operation.​
54 | ·​·​void·​h a ndl e_write(c o n s t·​a s i o:​:​e r r o r_c o d e&·​e)​;​ | 50 | ·​·​void·​do_write()​;​
55 |  | 51 |
56 | ·​·​/​/​/​·​Socket·​for·​the·​connection.​ | 52 | ·​·​/​/​/​·​Socket·​for·​the·​connection.​
57 | ·​·​asio:​:​ip:​:​tcp:​:​socket·​socket_;​ | 53 | ·​·​asio:​:​ip:​:​tcp:​:​socket·​socket_;​
58 |  | 54 |
59 | ·​·​/​/​/​·​The·​manager·​for·​this·​connection.​ | 55 | ·​·​/​/​/​·​The·​manager·​for·​this·​connection.​
60 | ·​·​connection_manager&·​connection_manager_;​ | 56 | ·​·​connection_manager&·​connection_manager_;​
61 |  | 57 |
62 | ·​·​/​/​/​·​The·​handler·​used·​to·​process·​the·​incoming·​request.​ | 58 | ·​·​/​/​/​·​The·​handler·​used·​to·​process·​the·​incoming·​request.​
63 | ·​·​request_handler&·​request_handler_;​ | 59 | ·​·​request_handler&·​request_handler_;​
64 |  | 60 |
65 | ·​·​/​/​/​·​Buffer·​for·​incoming·​data.​ | 61 | ·​·​/​/​/​·​Buffer·​for·​incoming·​data.​
66 | ·​·​b o ost:​:​array<char,​·​8192>·​buffer_;​ | 62 | ·​·​std:​:​array<char,​·​8192>·​buffer_;​
67 |  | 63 |
68 | ·​·​/​/​/​·​The·​incoming·​request.​ | 64 | ·​·​/​/​/​·​The·​incoming·​request.​
69 | ·​·​request·​request_;​ | 65 | ·​·​request·​request_;​
70 |  | 66 |
71 | ·​·​/​/​/​·​The·​parser·​for·​the·​incoming·​request.​ | 67 | ·​·​/​/​/​·​The·​parser·​for·​the·​incoming·​request.​
72 | ·​·​request_parser·​request_parser_;​ | 68 | ·​·​request_parser·​request_parser_;​
73 |  | 69 |
74 | ·​·​/​/​/​·​The·​reply·​to·​be·​sent·​back·​to·​the·​client.​ | 70 | ·​·​/​/​/​·​The·​reply·​to·​be·​sent·​back·​to·​the·​client.​
75 | ·​·​reply·​reply_;​ | 71 | ·​·​reply·​reply_;​
76 | };​ | 72 | };​
77 |  | 73 |
78 | typedef·​b o ost:​:​shared_ptr<connection​>·​connection_ptr;​ | 74 | typedef·​std:​:​shared_ptr<connection​>·​connection_ptr;​
79 |  | 75 |
80 | }·​/​/​·​namespace·​server | 76 | }·​/​/​·​namespace·​server
81 | }·​/​/​·​namespace·​http | 77 | }·​/​/​·​namespace·​http
82 |  | 78 |
83 | #endif·​/​/​·​HTTP_CONNECTION_HPP | 79 | #endif·​/​/​·​HTTP_CONNECTION_HPP