Repository navigation
Expand file tree
/
Copy pathserver.cpp
More file actions
96 lines (81 loc) · 3.8 KB
/
Copy pathserver.cpp
File metadata and controls
96 lines (81 loc) · 3.8 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
/*
+----------------------------------------------------------------------+
| HipHop for PHP |
+----------------------------------------------------------------------+
| Copyright (c) 2010-present Facebook, Inc. (http://www.facebook.com) |
+----------------------------------------------------------------------+
| This source file is subject to version 3.01 of the PHP license, |
| that is bundled with this package in the file LICENSE, and is |
| available through the world-wide-web at the following url: |
| http://www.php.net/license/3_01.txt |
| If you did not receive a copy of the PHP license and are unable to |
| obtain it through the world-wide-web, please send a note to |
| license@php.net so we can mail you a copy immediately. |
+----------------------------------------------------------------------+
*/
#include "hphp/runtime/server/server.h"
#include "hphp/runtime/server/satellite-server.h"
#include "hphp/runtime/base/preg.h"
#include <signal.h>
///////////////////////////////////////////////////////////////////////////////
// statics
namespace HPHP {
///////////////////////////////////////////////////////////////////////////////
bool Server::StackTraceOnError = true;
///////////////////////////////////////////////////////////////////////////////
Server::Server(const std::string &address, int port)
: m_address(address), m_port(port),
m_urlChecker(SatelliteServerInfo::checkMainURL) {
}
///////////////////////////////////////////////////////////////////////////////
ServerPtr ServerFactory::createServer(const std::string &address,
uint16_t port,
int maxThreads,
int initThreads) {
return createServer(ServerOptions{address, port, maxThreads, initThreads});
}
ServerFactoryRegistry::ServerFactoryRegistry()
: m_lock(false) {
}
ServerFactoryRegistry *ServerFactoryRegistry::getInstance() {
static ServerFactoryRegistry singleton;
return &singleton;
}
ServerPtr ServerFactoryRegistry::createServer(const std::string &type,
const std::string &address,
uint16_t port,
int maxThreads,
int initThreads) {
auto factory = getInstance()->getFactory(type);
return factory->createServer(
ServerOptions{address, port, maxThreads, initThreads});
}
void ServerFactoryRegistry::registerFactory(const std::string &name,
const ServerFactoryPtr &factory) {
Lock lock(m_lock);
auto ret = m_factories.insert(std::make_pair(name, factory));
if (!ret.second) {
throw ServerException("a factory already exists for server type \"%s\"",
name.c_str());
}
}
ServerFactoryPtr ServerFactoryRegistry::getFactory(const std::string &name) {
Lock lock(m_lock);
auto it = m_factories.find(name);
if (it == m_factories.end()) {
if (name == "libevent") {
throw ServerException(
"HHVM no longer supports the built-in webserver as of 3.0.0. Please "
"use your own webserver (nginx or apache) talking to HHVM over "
"fastcgi. https://github.com/facebook/hhvm/wiki/FastCGI");
}
throw ServerException("no factory for server type \"%s\"", name.c_str());
}
return it->second;
}
///////////////////////////////////////////////////////////////////////////////
ServerException::ServerException(const char *fmt, ...) {
va_list ap; va_start(ap, fmt); format(fmt, ap); va_end(ap);
}
///////////////////////////////////////////////////////////////////////////////
}