]>
Commit | Line | Data |
---|---|---|
1 | /* | |
2 | * This file is part of PowerDNS or dnsdist. | |
3 | * Copyright -- PowerDNS.COM B.V. and its contributors | |
4 | * | |
5 | * This program is free software; you can redistribute it and/or modify | |
6 | * it under the terms of version 2 of the GNU General Public License as | |
7 | * published by the Free Software Foundation. | |
8 | * | |
9 | * In addition, for the avoidance of any doubt, permission is granted to | |
10 | * link this program with OpenSSL and to (re)distribute the binaries | |
11 | * produced as the result of such linking. | |
12 | * | |
13 | * This program is distributed in the hope that it will be useful, | |
14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
16 | * GNU General Public License for more details. | |
17 | * | |
18 | * You should have received a copy of the GNU General Public License | |
19 | * along with this program; if not, write to the Free Software | |
20 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. | |
21 | */ | |
22 | #ifndef PDNS_WSRECURSOR_HH | |
23 | #define PDNS_WSRECURSOR_HH | |
24 | ||
25 | #include <boost/utility.hpp> | |
26 | #include "namespaces.hh" | |
27 | #include "mplexer.hh" | |
28 | #include "webserver.hh" | |
29 | ||
30 | class HttpRequest; | |
31 | class HttpResponse; | |
32 | ||
33 | class AsyncServer : public Server { | |
34 | public: | |
35 | AsyncServer(const string &localaddress, int port) : Server(localaddress, port) { }; | |
36 | ||
37 | friend void AsyncServerNewConnectionMT(void *p); | |
38 | ||
39 | typedef boost::function< void(std::shared_ptr<Socket>) > newconnectioncb_t; | |
40 | void asyncWaitForConnections(FDMultiplexer* fdm, const newconnectioncb_t& callback); | |
41 | ||
42 | private: | |
43 | void newConnection(); | |
44 | ||
45 | newconnectioncb_t d_asyncNewConnectionCallback; | |
46 | }; | |
47 | ||
48 | class AsyncWebServer : public WebServer | |
49 | { | |
50 | public: | |
51 | AsyncWebServer(FDMultiplexer* fdm, const string &listenaddress, int port) : | |
52 | WebServer(listenaddress, port), d_fdm(fdm) { }; | |
53 | void go(); | |
54 | ||
55 | private: | |
56 | FDMultiplexer* d_fdm; | |
57 | void serveConnection(std::shared_ptr<Socket> socket) const; | |
58 | ||
59 | protected: | |
60 | virtual std::shared_ptr<Server> createServer() override { | |
61 | return std::make_shared<AsyncServer>(d_listenaddress, d_port); | |
62 | }; | |
63 | }; | |
64 | ||
65 | class RecursorWebServer : public boost::noncopyable | |
66 | { | |
67 | public: | |
68 | explicit RecursorWebServer(FDMultiplexer* fdm); | |
69 | void jsonstat(HttpRequest* req, HttpResponse *resp); | |
70 | ||
71 | private: | |
72 | AsyncWebServer* d_ws; | |
73 | }; | |
74 | ||
75 | #endif /* PDNS_WSRECURSOR_HH */ |