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/Http/IOStream.h>
34 #include <Pt/Connectable.h>
35 #include <Pt/NonCopyable.h>
36 #include <cstddef>
37 
38 namespace Pt {
39 
40 namespace System {
41 class EventLoop;
42 }
43 
44 namespace Net {
45 class Endpoint;
46 class TcpServerOptions;
47 }
48 
49 namespace Ssl {
50 class Context;
51 }
52 
53 namespace Http {
54 
57 class PT_HTTP_API Server : public Connectable
58  , private NonCopyable
59 {
60  public:
63  Server();
64 
67  explicit Server(System::EventLoop& loop);
68 
72 
76 
80 
84 
87  std::size_t timeout() const;
88 
91  void setTimeout(std::size_t ms);
92 
95  void setSecure(Ssl::Context& ctx);
96 
99  std::size_t maxThreads() const;
100 
103  void setMaxThreads(std::size_t m);
104 
107  std::size_t keepAliveTimeout() const;
108 
111  void setKeepAliveTimeout(std::size_t ms);
112 
115  std::size_t maxRequestSize() const;
116 
119  void setMaxRequestSize(std::size_t maxSize);
120 
123  void listen(const Net::Endpoint& ep);
124 
127  void listen(const Net::Endpoint& ep, const Net::TcpServerOptions& opts);
128 
131  void cancel();
132 
135  void addServlet(Servlet& servlet);
136 
139  void removeServlet(Servlet& servlet);
140 
143  void shutdownServlet(Servlet& servlet, bool shutdown);
144 
147  bool isServletIdle(Servlet& servlet);
148 
150  Servlet* getServlet(const Request& request);
151 
152  Signal<IOStream*>& upgradeRequested();
153 
154  private:
155  class ServerImpl* _impl;
156 };
157 
158 } // namespace Http
159 
160 } // namespace Pt
161 
162 #endif // Pt_Http_Server_h
Core module.
Definition: Allocator.h:33
Server()
Default Constructor.
void setTimeout(std::size_t ms)
Sets the timeout in msecs.
HTTP request message.
Definition: Request.h:44
void setMaxThreads(std::size_t m)
Sets the maximum number of server threads.
Multicast Signal to call multiple slots.
Definition: Api-Signal.h:111
void cancel()
Cancel all operations.
void addServlet(Servlet &servlet)
Adds a servlet.
Servlet for HTTP services.
Definition: Servlet.h:53
void setActive(System::EventLoop &loop)
Sets the event loop to use.
TCP server options.
Definition: TcpServer.h:44
std::size_t timeout() const
Returns the timeout in msecs.
Connection Management for Signal and Slot Objects.
Definition: Connectable.h:50
void setMaxRequestSize(std::size_t maxSize)
Sets the maximum size of a request in bytes.
Represents a Network Host.
Definition: Endpoint.h:47
std::size_t maxRequestSize() const
Returns the maximum size of a request in bytes.
System::EventLoop * loop()
Returns the used event loop.
std::size_t keepAliveTimeout() const
Returns the keepalive timeout in msecs.
An HTTP server.
Definition: Server.h:59
Thread-safe event loop supporting I/O multiplexing and Timers.
Definition: EventLoop.h:74
Server(System::EventLoop &loop)
Construct with event loop.
void removeServlet(Servlet &servlet)
Removes a servlet.
std::size_t maxThreads() const
Returns the maximum number of server threads.
void setKeepAliveTimeout(std::size_t ms)
Sets the keepalive timeout in msecs.
Protects derived classes from being copied.
Definition: NonCopyable.h:54
void listen(const Net::Endpoint &ep)
Start listening on endpoint.
~Server()
Destructor.
void setSecure(Ssl::Context &ctx)
Enables to use HTTPS.
void listen(const Net::Endpoint &ep, const Net::TcpServerOptions &opts)
Start listening on endpoint.
Server(System::EventLoop &loop, const Net::Endpoint &ep)
Construct with event loop and listen endpoint.
Context for SSL connections.
Definition: Context.h:80