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
38namespace Pt {
39
40namespace System {
41class EventLoop;
42}
43
44namespace Net {
45class Endpoint;
47}
48
49namespace Ssl {
50class Context;
51}
52
53namespace Http {
54
81class PT_HTTP_API Server : public Connectable
82 , private NonCopyable
83{
84 public:
88
92
96
100
104
108
111 std::size_t timeout() const;
112
115 void setTimeout(std::size_t ms);
116
120
123 std::size_t maxThreads() const;
124
127 void setMaxThreads(std::size_t m);
128
131 std::size_t keepAliveTimeout() const;
132
135 void setKeepAliveTimeout(std::size_t ms);
136
139 std::size_t maxRequestSize() const;
140
143 void setMaxRequestSize(std::size_t maxSize);
144
147 void listen(const Net::Endpoint& ep);
148
151 void listen(const Net::Endpoint& ep, const Net::TcpServerOptions& opts);
152
155 void cancel();
156
159 void addServlet(Servlet& servlet);
160
163 void removeServlet(Servlet& servlet);
164
167 void shutdownServlet(Servlet& servlet, bool shutdown);
168
171 bool isServletIdle(Servlet& servlet);
172
174 Servlet* getServlet(const Request& request);
175
176 private:
177 class ServerImpl* _impl;
178};
179
180} // namespace Http
181
182} // namespace Pt
183
184#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:45
SSL/TLS streams, certificates and contexts.
Definition Client.h:50
System programming
Definition Connection.h:26
Core module.
Definition Allocator.h:33