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
37namespace Pt {
38
39namespace System {
40class EventLoop;
41}
42
43namespace Net {
44class Endpoint;
46}
47
48namespace Ssl {
49class Context;
50}
51
52namespace Http {
53
80class PT_HTTP_API Server : public Connectable
81 , private NonCopyable
82{
83 public:
87
91
95
99
103
107
110 std::size_t timeout() const;
111
114 void setTimeout(std::size_t ms);
115
119
122 std::size_t maxThreads() const;
123
126 void setMaxThreads(std::size_t m);
127
130 std::size_t keepAliveTimeout() const;
131
134 void setKeepAliveTimeout(std::size_t ms);
135
138 std::size_t maxRequestSize() const;
139
142 void setMaxRequestSize(std::size_t maxSize);
143
146 void listen(const Net::Endpoint& ep);
147
150 void listen(const Net::Endpoint& ep, const Net::TcpServerOptions& opts);
151
154 void cancel();
155
158 void addServlet(Servlet& servlet);
159
162 void removeServlet(Servlet& servlet);
163
166 void shutdownServlet(Servlet& servlet, bool shutdown);
167
170 bool isServletIdle(Servlet& servlet);
171
173 Servlet* getServlet(const Request& request);
174
175 private:
176 class ServerImpl* _impl;
177};
178
179} // namespace Http
180
181} // namespace Pt
182
183#endif // Pt_Http_Server_h
Connectable()
Default constructor.
HTTP request message.
Definition Request.h:65
void cancel()
Cancel all operations.
void setSecure(Ssl::Context &ctx)
Enables HTTPS with ctx.
std::size_t maxRequestSize() const
Returns the maximum size of a request in bytes.
void listen(const Net::Endpoint &ep)
Start listening on endpoint.
void setMaxThreads(std::size_t m)
Sets the maximum number of server threads.
void setTimeout(std::size_t ms)
Sets the timeout in msecs.
void setMaxRequestSize(std::size_t maxSize)
Sets the maximum size of a request in bytes.
void removeServlet(Servlet &servlet)
Removes a servlet.
std::size_t timeout() const
Returns the timeout in msecs.
std::size_t keepAliveTimeout() const
Returns the keepalive timeout in msecs.
System::EventLoop * loop()
Returns the used event loop.
void setActive(System::EventLoop &loop)
Sets the event loop to use.
~Server()
Destructor.
Server(System::EventLoop &loop, const Net::Endpoint &ep)
Construct with event loop and listen endpoint.
void setKeepAliveTimeout(std::size_t ms)
Sets the keepalive timeout in msecs.
Server(System::EventLoop &loop)
Construct with event loop.
void addServlet(Servlet &servlet)
Adds a servlet.
void listen(const Net::Endpoint &ep, const Net::TcpServerOptions &opts)
Start listening on endpoint.
std::size_t maxThreads() const
Returns the maximum number of server threads.
Server()
Default Constructor.
Maps requests to a service.
Definition Servlet.h:80
Host and service address.
Definition Endpoint.h:77
TCP server listen options.
Definition TcpServer.h:46
NonCopyable()
Default constructor.
Definition NonCopyable.h:63
Shared configuration for SSL connections.
Definition Context.h:113
Event loop of a thread or process.
Definition EventLoop.h:83
HTTP clients and servers.
TCP and UDP network sockets.
Definition Client.h:46
SSL/TLS streams, certificates and contexts.
Definition Client.h:51
System programming
Definition Connection.h:26
Core module.
Definition Allocator.h:33