src/​examples/​cpp03/​http/​server/​server.​hpp | src/​examples/​cpp11/​http/​server/​server.​hpp
--- | ---
⋮ | ⋮
1 | /​/​ | 1 | /​/​
2 | /​/​·​server.​hpp | 2 | /​/​·​server.​hpp
3 | /​/​·​~~~~~~~~~~ | 3 | /​/​·​~~~~~~~~~~
4 | /​/​ | 4 | /​/​
5 | /​/​·​Copyright·​(c)​·​2003-​2021·​Christopher·​M.​·​Kohlhoff·​(chris·​at·​kohlhoff·​dot·​com)​ | 5 | /​/​·​Copyright·​(c)​·​2003-​2021·​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_SERVER_HPP | 11 | #ifndef·​HTTP_SERVER_HPP
12 | #define·​HTTP_SERVER_HPP | 12 | #define·​HTTP_SERVER_HPP
13 |  | 13 |
14 | #include·​<asio.​hpp> | 14 | #include·​<asio.​hpp>
15 | #include·​<string> | 15 | #include·​<string>
16 | #include·​<boost/​noncopyable.​hpp> |
17 | #include·​"connection.​hpp" | 16 | #include·​"connection.​hpp"
18 | #include·​"connection_manager.​hpp" | 17 | #include·​"connection_manager.​hpp"
19 | #include·​"request_handler.​hpp" | 18 | #include·​"request_handler.​hpp"
20 |  | 19 |
21 | namespace·​http·​{ | 20 | namespace·​http·​{
22 | namespace·​server·​{ | 21 | namespace·​server·​{
23 |  | 22 |
24 | /​/​/​·​The·​top-​level·​class·​of·​the·​HTTP·​server.​ | 23 | /​/​/​·​The·​top-​level·​class·​of·​the·​HTTP·​server.​
25 | class·​server | 24 | class·​server
26 | ·​·​:​·​private·​boost:​:​noncopyable |
27 | { | 25 | {
28 | public:​ | 26 | public:​
| 27 | ·​·​server(const·​server&)​·​=·​delete;​
| 28 | ·​·​server&·​operator=(const·​server&)​·​=·​delete;​
| 29 |
29 | ·​·​/​/​/​·​Construct·​the·​server·​to·​listen·​on·​the·​specified·​TCP·​address·​and·​port,​·​and | 30 | ·​·​/​/​/​·​Construct·​the·​server·​to·​listen·​on·​the·​specified·​TCP·​address·​and·​port,​·​and
30 | ·​·​/​/​/​·​serve·​up·​files·​from·​the·​given·​directory.​ | 31 | ·​·​/​/​/​·​serve·​up·​files·​from·​the·​given·​directory.​
31 | ·​·​explicit·​server(const·​std:​:​string&·​address,​·​const·​std:​:​string&·​port,​ | 32 | ·​·​explicit·​server(const·​std:​:​string&·​address,​·​const·​std:​:​string&·​port,​
32 | ·​·​·​·​·​·​const·​std:​:​string&·​doc_root)​;​ | 33 | ·​·​·​·​·​·​const·​std:​:​string&·​doc_root)​;​
33 |  | 34 |
34 | ·​·​/​/​/​·​Run·​the·​server's·​io_context·​loop.​ | 35 | ·​·​/​/​/​·​Run·​the·​server's·​io_context·​loop.​
35 | ·​·​void·​run()​;​ | 36 | ·​·​void·​run()​;​
36 |  | 37 |
37 | private:​ | 38 | private:​
38 | ·​·​/​/​/​·​I n i t i a t e·​an·​asynchronous·​accept·​operation.​ | 39 | ·​·​/​/​/​·​P e r f o r m·​an·​asynchronous·​accept·​operation.​
39 | ·​·​void·​s t a r t_accept()​;​ | 40 | ·​·​void·​d o_accept()​;​
40 |  |
41 | ·​·​/​/​/​·​H a n d l e·​c o m p l e t i o n·​o f·​a n·​a s y n c h r o n o u s·​a c c e p t·​o p e r a t i o n.​ |
42 | ·​·​v o i d·​h a n d l e_a c c e p t(c o n s t·​a s i o:​:​e r r o r_c o d e&·​e)​;​ |
43 |  | 41 |
44 | ·​·​/​/​/​·​Han d l e·​a·​request·​to·​stop·​the·​server.​ | 42 | ·​·​/​/​/​·​Wai t·​f o r·​a·​request·​to·​stop·​the·​server.​
45 | ·​·​void·​han d l e_stop()​;​ | 43 | ·​·​void·​d o_aw a i t_stop()​;​
46 |  | 44 |
47 | ·​·​/​/​/​·​The·​io_context·​used·​to·​perform·​asynchronous·​operations.​ | 45 | ·​·​/​/​/​·​The·​io_context·​used·​to·​perform·​asynchronous·​operations.​
48 | ·​·​asio:​:​io_context·​io_context_;​ | 46 | ·​·​asio:​:​io_context·​io_context_;​
49 |  | 47 |
50 | ·​·​/​/​/​·​The·​signal_set·​is·​used·​to·​register·​for·​process·​termination·​notifications.​ | 48 | ·​·​/​/​/​·​The·​signal_set·​is·​used·​to·​register·​for·​process·​termination·​notifications.​
51 | ·​·​asio:​:​signal_set·​signals_;​ | 49 | ·​·​asio:​:​signal_set·​signals_;​
52 |  | 50 |
53 | ·​·​/​/​/​·​Acceptor·​used·​to·​listen·​for·​incoming·​connections.​ | 51 | ·​·​/​/​/​·​Acceptor·​used·​to·​listen·​for·​incoming·​connections.​
54 | ·​·​asio:​:​ip:​:​tcp:​:​acceptor·​acceptor_;​ | 52 | ·​·​asio:​:​ip:​:​tcp:​:​acceptor·​acceptor_;​
55 |  | 53 |
56 | ·​·​/​/​/​·​The·​connection·​manager·​which·​owns·​all·​live·​connections.​ | 54 | ·​·​/​/​/​·​The·​connection·​manager·​which·​owns·​all·​live·​connections.​
57 | ·​·​connection_manager·​connection_manager_;​ | 55 | ·​·​connection_manager·​connection_manager_;​
58 |  | 56 |
59 | ·​·​/​/​/​·​The·​next·​connection·​to·​be·​accepted.​ |
60 | ·​·​connection_ptr·​new_connection_;​ |
61 |  |
62 | ·​·​/​/​/​·​The·​handler·​for·​all·​incoming·​requests.​ | 57 | ·​·​/​/​/​·​The·​handler·​for·​all·​incoming·​requests.​
63 | ·​·​request_handler·​request_handler_;​ | 58 | ·​·​request_handler·​request_handler_;​
64 | };​ | 59 | };​
65 |  | 60 |
66 | }·​/​/​·​namespace·​server | 61 | }·​/​/​·​namespace·​server
67 | }·​/​/​·​namespace·​http | 62 | }·​/​/​·​namespace·​http
68 |  | 63 |
69 | #endif·​/​/​·​HTTP_SERVER_HPP | 64 | #endif·​/​/​·​HTTP_SERVER_HPP