|
26 | 26 | #include <string> // for string
|
27 | 27 | #include <vector> // for vector<>
|
28 | 28 |
|
29 |
| -// Requires: cppnetlib |
30 |
| -#include <boost/network/include/http/server.hpp> |
31 |
| -#include <boost/network/utils/thread_pool.hpp> |
| 29 | +#include <oatpp/network/Server.hpp> |
32 | 30 |
|
33 | 31 | #include "oak/registrar.hpp" // for StaticRegistrar, BufferRegistrar
|
34 |
| -#include "oak/route_muxer.hpp" // for Muxer<> |
35 | 32 |
|
36 | 33 | namespace oak {
|
37 | 34 |
|
38 |
| -// These forward-declarations are a necessary evil: |
39 |
| -class ServerImplHandler; |
40 |
| -using ServerImpl = boost::network::http::server<ServerImplHandler>; |
41 |
| - |
42 |
| -/** |
43 |
| - * ServerImplHandler is the main request handler for the server. |
44 |
| - * |
45 |
| - * It implements an interface defined by boost::network::http::server. |
46 |
| - */ |
47 |
| -class ServerImplHandler { |
48 |
| - public: |
49 |
| - ServerImplHandler(); |
50 |
| - |
51 |
| - /** |
52 |
| - * Handle every request from the server. |
53 |
| - * |
54 |
| - * Every single request that passes through the server has to go through this |
55 |
| - * handler. If the muxer has an endpoint that matches the request, then it |
56 |
| - * gets passed through. The muxer has a default endpoint, so the nominal case |
57 |
| - * is that every request is passed to some handler from the muxer. |
58 |
| - */ |
59 |
| - void operator()(ServerImpl::request const&, ServerImpl::connection_ptr); |
60 |
| - |
61 |
| - /** |
62 |
| - * Log an error from the server. |
63 |
| - */ |
64 |
| - void log(const ServerImpl::string_type& msg); |
65 |
| - |
66 |
| - /** |
67 |
| - * Add a handler for a specific endpoint. |
68 |
| - */ |
69 |
| - void add(const std::string& key, Handler h); |
70 |
| - |
71 |
| - /** |
72 |
| - * Return a list of all registered endpoints. |
73 |
| - */ |
74 |
| - std::vector<std::string> endpoints() const { return muxer.routes(); } |
75 |
| - |
76 |
| - /** |
77 |
| - * Return endpoint data in json format. |
78 |
| - */ |
79 |
| - cloe::Json endpoints_to_json(const std::vector<std::string>& endpoints) const; |
80 |
| - |
81 |
| - private: |
82 |
| - Muxer<Handler> muxer; |
83 |
| -}; |
| 35 | +class GreedyHandler; |
84 | 36 |
|
85 | 37 | /**
|
86 | 38 | * A Server accepts and serves endpoints for Handlers.
|
@@ -169,10 +121,8 @@ class Server {
|
169 | 121 |
|
170 | 122 | // State
|
171 | 123 | bool listening_;
|
172 |
| - ServerImplHandler handler_; |
173 |
| - std::unique_ptr<ServerImpl::options> options_; |
174 |
| - std::unique_ptr<ServerImpl> server_; |
175 |
| - std::unique_ptr<boost::thread> thread_; |
| 124 | + std::shared_ptr<oatpp::network::Server> server_; |
| 125 | + std::shared_ptr<GreedyHandler> handler_; |
176 | 126 | };
|
177 | 127 |
|
178 | 128 | } // namespace oak
|
0 commit comments