proxygen
StaticServer.cpp File Reference

Go to the source code of this file.

Typedefs

using Protocol = HTTPServer::Protocol
 

Functions

 DEFINE_int32 (http_port, 11000,"Port to listen on with HTTP protocol")
 
 DEFINE_int32 (h2_port, 11002,"Port to listen on with HTTP/2 protocol")
 
 DEFINE_string (ip,"localhost","IP/Hostname to bind to")
 
 DEFINE_int32 (threads, 0,"Number of threads to listen on. Numbers <= 0 ""will use the number of cores on this machine.")
 
int main (int argc, char *argv[])
 

Typedef Documentation

Definition at line 30 of file StaticServer.cpp.

Function Documentation

DEFINE_int32 ( http_port  ,
11000  ,
"Port to listen on with HTTP protocol"   
)
DEFINE_int32 ( h2_port  ,
11002  ,
"Port to listen on with HTTP/2 protocol"   
)
DEFINE_int32 ( threads  ,
,
"Number of threads to listen on. Numbers <= 0 ""will use the number of cores on this machine."   
)
DEFINE_string ( ip  ,
"localhost"  ,
"IP/Hostname to bind to"   
)
int main ( int  argc,
char *  argv[] 
)

Definition at line 53 of file StaticServer.cpp.

References proxygen::RequestHandlerChain::addThen(), proxygen::HTTPServer::bind(), proxygen::HTTPServerOptions::enableContentCompression, proxygen::HTTPServerOptions::h2cEnabled, proxygen::HTTPServerOptions::handlerFactories, proxygen::HTTPServerOptions::idleTimeout, folly::init(), folly::gen::move, folly::setCPUExecutor(), proxygen::HTTPServerOptions::shutdownOn, proxygen::HTTPServer::start(), folly::pushmi::detail::t, and proxygen::HTTPServerOptions::threads.

53  {
54  folly::init(&argc, &argv, true);
55 
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},
59  };
60 
61  if (FLAGS_threads <= 0) {
62  FLAGS_threads = sysconf(_SC_NPROCESSORS_ONLN);
63  CHECK_GT(FLAGS_threads, 0);
64  }
65 
66  HTTPServerOptions options;
67  options.threads = static_cast<size_t>(FLAGS_threads);
68  options.idleTimeout = std::chrono::milliseconds(60000);
69  options.shutdownOn = {SIGINT, SIGTERM};
70  options.enableContentCompression = false;
72  .addThen<StaticHandlerFactory>()
73  .build();
74  options.h2cEnabled = true;
75 
76  auto diskIOThreadPool = std::make_shared<folly::CPUThreadPoolExecutor>(
77  FLAGS_threads,
78  std::make_shared<folly::NamedThreadFactory>("StaticDiskIOThread"));
79  folly::setCPUExecutor(diskIOThreadPool);
80 
81  HTTPServer server(std::move(options));
82  server.bind(IPs);
83 
84  // Start HTTPServer mainloop in a separate thread
85  std::thread t([&] () {
86  server.start();
87  });
88 
89  t.join();
90  return 0;
91 }
std::chrono::milliseconds idleTimeout
constexpr detail::Map< Move > move
Definition: Base-inl.h:2567
RequestHandlerChain & addThen(Args &&...args)
void init(int *argc, char ***argv, bool removeFlags)
Definition: Init.cpp:34
char ** argv
std::vector< std::unique_ptr< RequestHandlerFactory > > handlerFactories
std::vector< int > shutdownOn
void setCPUExecutor(std::weak_ptr< Executor > executor)