src/​examples/​cpp03/​http/​server/​server.​hppsrc/​examples/​cpp11/​http/​server/​server.​hpp
1 /​/​1 /​/​
2 /​/​·​server.​hpp2 /​/​·​server.​hpp
3 /​/​·​~~~~~~~~~~3 /​/​·​~~~~~~~~~~
4 /​/​4 /​/​
5 /​/​·​Copyright·​(c)​·​2003-​2018·​Christopher·​M.​·​Kohlhoff·​(chris·​at·​kohlhoff·​dot·​com)​5 /​/​·​Copyright·​(c)​·​2003-​2018·​Christopher·​M.​·​Kohlhoff·​(chris·​at·​kohlhoff·​dot·​com)​
6 /​/​6 /​/​
7 /​/​·​Distributed·​under·​the·​Boost·​Software·​License,​·​Version·​1.​0.​·​(See·​accompanying7 /​/​·​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_HPP11 #ifndef·​HTTP_SERVER_HPP
12 #define·​HTTP_SERVER_HPP12 #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·​server24 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,​·​and30 ··​/​/​/​·​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 ··​/​/​/​·Initiate·​an·​asynchronous·​accept·​operation.​39 ··​/​/​/​·Perform·​an·​asynchronous·​accept·​operation.​
39 ··​void·start_accept()​;​40 ··​void·do_accept()​;​
40
41 ··/​/​/​·Handle·completion·of·an·asynchronous·accept·operation.​
42 ··void·handle_accept(const·asio:​:​error_code&·e)​;​
43 41
44 ··​/​/​/​·Handle·​a·​request·​to·​stop·​the·​server.​42 ··​/​/​/​·Wait·for·​a·​request·​to·​stop·​the·​server.​
45 ··​void·handle_stop()​;​43 ··​void·do_await_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·​server61 }·​/​/​·​namespace·​server
67 }·​/​/​·​namespace·​http62 }·​/​/​·​namespace·​http
68 63
69 #endif·​/​/​·​HTTP_SERVER_HPP64 #endif·​/​/​·​HTTP_SERVER_HPP