proxygen
ProxyServer.cpp File Reference

Go to the source code of this file.

Classes

class  ProxyHandlerFactory
 
struct  ProxyHandlerFactory::TimerWrapper
 

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.")
 
 DEFINE_int32 (server_timeout, 60,"How long to wait for a server response (sec)")
 
int main (int argc, char *argv[])
 

Typedef Documentation

Definition at line 27 of file ProxyServer.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_int32 ( server_timeout  ,
60  ,
"How long to wait for a server response (sec)"   
)
DEFINE_string ( ip  ,
"localhost"  ,
"IP/Hostname to bind to"   
)
int main ( int  argc,
char *  argv[] 
)

Definition at line 65 of file ProxyServer.cpp.

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

65  {
66  gflags::ParseCommandLineFlags(&argc, &argv, true);
67  google::InitGoogleLogging(argv[0]);
68  google::InstallFailureSignalHandler();
69 
70  std::vector<HTTPServer::IPConfig> IPs = {
71  {SocketAddress(FLAGS_ip, FLAGS_http_port, true), Protocol::HTTP},
72  {SocketAddress(FLAGS_ip, FLAGS_h2_port, true), Protocol::HTTP2},
73  };
74 
75  if (FLAGS_threads <= 0) {
76  FLAGS_threads = sysconf(_SC_NPROCESSORS_ONLN);
77  CHECK(FLAGS_threads > 0);
78  }
79 
80  HTTPServerOptions options;
81  options.threads = static_cast<size_t>(FLAGS_threads);
82  options.idleTimeout = std::chrono::milliseconds(60000);
83  options.shutdownOn = {SIGINT, SIGTERM};
84  options.enableContentCompression = false;
87  .build();
88  options.h2cEnabled = true;
89  options.supportsConnect = true;
90 
91  HTTPServer server(std::move(options));
92  server.bind(IPs);
93 
94  // Start HTTPServer mainloop in a separate thread
95  std::thread t([&] () {
96  server.start();
97  });
98 
99  t.join();
100  return 0;
101 }
std::chrono::milliseconds idleTimeout
constexpr detail::Map< Move > move
Definition: Base-inl.h:2567
RequestHandlerChain & addThen(Args &&...args)
char ** argv
std::vector< std::unique_ptr< RequestHandlerFactory > > handlerFactories
std::vector< int > shutdownOn