32 DEFINE_int32(http_port, 11000,
"Port to listen on with HTTP protocol");
33 DEFINE_int32(h2_port, 11002,
"Port to listen on with HTTP/2 protocol");
36 "will use the number of cores on this machine.");
44 void onServerStop()
noexcept override {}
56 std::vector<HTTPServer::IPConfig> IPs = {
57 {
SocketAddress(FLAGS_ip, FLAGS_http_port,
true), Protocol::HTTP},
58 {
SocketAddress(FLAGS_ip, FLAGS_h2_port,
true), Protocol::HTTP2},
61 if (FLAGS_threads <= 0) {
62 FLAGS_threads = sysconf(_SC_NPROCESSORS_ONLN);
63 CHECK_GT(FLAGS_threads, 0);
67 options.
threads =
static_cast<size_t>(FLAGS_threads);
68 options.
idleTimeout = std::chrono::milliseconds(60000);
72 .
addThen<StaticHandlerFactory>()
76 auto diskIOThreadPool = std::make_shared<folly::CPUThreadPoolExecutor>(
78 std::make_shared<folly::NamedThreadFactory>(
"StaticDiskIOThread"));
85 std::thread
t([&] () {
int main(int argc, char *argv[])
void start(std::function< void()> onSuccess=nullptr, std::function< void(std::exception_ptr)> onError=nullptr)
std::chrono::milliseconds idleTimeout
constexpr detail::Map< Move > move
void bind(std::vector< IPConfig > &&addrs)
RequestHandlerChain & addThen(Args &&...args)
requires E e noexcept(noexcept(s.error(std::move(e))))
HTTPServer::Protocol Protocol
std::vector< std::thread::id > threads
void init(int *argc, char ***argv, bool removeFlags)
DEFINE_string(ip,"localhost","IP/Hostname to bind to")
std::vector< std::unique_ptr< RequestHandlerFactory > > handlerFactories
DEFINE_int32(http_port, 11000,"Port to listen on with HTTP protocol")
std::vector< int > shutdownOn
void setCPUExecutor(std::weak_ptr< Executor > executor)
bool enableContentCompression