Server.h
1 /*
2  * Copyright (C) 2011-2012 by Marc Boris Duerner
3  *
4  * This library is free software; you can redistribute it and/or
5  * modify it under the terms of the GNU Lesser General Public
6  * License as published by the Free Software Foundation; either
7  * version 2.1 of the License, or (at your option) any later version.
8  *
9  * As a special exception, you may use this file as part of a free
10  * software library without restriction. Specifically, if other files
11  * instantiate templates or use macros or inline functions from this
12  * file, or you compile this file and link it with other files to
13  * produce an executable, this file does not by itself cause the
14  * resulting executable to be covered by the GNU General Public
15  * License. This exception does not however invalidate any other
16  * reasons why the executable file might be covered by the GNU Library
17  * General Public License.
18  *
19  * This library is distributed in the hope that it will be useful,
20  * but WITHOUT ANY WARRANTY; without even the implied warranty of
21  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
22  * Lesser General Public License for more details.
23  *
24  * You should have received a copy of the GNU Lesser General Public
25  * License along with this library; if not, write to the Free Software
26  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
27  */
28 
29 #ifndef Pt_Http_Server_h
30 #define Pt_Http_Server_h
31 
32 #include <Pt/Http/Api.h>
33 #include <Pt/Connectable.h>
34 #include <Pt/NonCopyable.h>
35 #include <cstddef>
36 
37 namespace Pt {
38 
39 namespace System {
40 class EventLoop;
41 }
42 
43 namespace Net {
44 class Endpoint;
45 class TcpServerOptions;
46 }
47 
48 namespace Ssl {
49 class Context;
50 }
51 
52 namespace Http {
53 
56 class PT_HTTP_API Server : public Connectable
57  , private NonCopyable
58 {
59  public:
62  Server();
63 
66  explicit Server(System::EventLoop& loop);
67 
70  Server(System::EventLoop& loop, const Net::Endpoint& ep);
71 
74  ~Server();
75 
78  System::EventLoop* loop();
79 
82  void setActive(System::EventLoop& loop);
83 
86  std::size_t timeout() const;
87 
90  void setTimeout(std::size_t ms);
91 
94  void setSecure(Ssl::Context& ctx);
95 
98  std::size_t maxThreads() const;
99 
102  void setMaxThreads(std::size_t m);
103 
106  std::size_t keepAliveTimeout() const;
107 
110  void setKeepAliveTimeout(std::size_t ms);
111 
114  std::size_t maxRequestSize() const;
115 
118  void setMaxRequestSize(std::size_t maxSize);
119 
122  void listen(const Net::Endpoint& ep);
123 
126  void listen(const Net::Endpoint& ep, const Net::TcpServerOptions& opts);
127 
130  void cancel();
131 
134  void addServlet(Servlet& servlet);
135 
138  void removeServlet(Servlet& servlet);
139 
142  void shutdownServlet(Servlet& servlet, bool shutdown);
143 
146  bool isServletIdle(Servlet& servlet);
147 
149  Servlet* getServlet(const Request& request);
150 
151  private:
152  class ServerImpl* _impl;
153 };
154 
155 } // namespace Http
156 
157 } // namespace Pt
158 
159 #endif // Pt_Http_Server_h
TCP server options.
Definition: TcpServer.h:43
HTTP request message.
Definition: Request.h:43
Protects derived classes from being copied.
Definition: NonCopyable.h:54
An HTTP server.
Definition: Server.h:56
Connection Management for Signal and Slot Objects.
Definition: Connectable.h:49
Servlet for HTTP services.
Definition: Servlet.h:52
Context for SSL connections.
Definition: Context.h:76
Represents a Network Host.
Definition: Endpoint.h:46
Thread-safe event loop supporting I/O multiplexing and Timers.
Definition: EventLoop.h:72