Exemplo n.º 1
0
static ServerPtr runServer() {
  for (s_server_port = PORT_MIN; s_server_port <= PORT_MAX; s_server_port++) {
    try {
      ServerPtr server(new TypedServer<LibEventServer, TestCurlRequestHandler>
                       ("127.0.0.1", s_server_port, 4, -1));
      server->start();
      return server;

    } catch (const FailedToListenException& e) {
      if (s_server_port == PORT_MAX) throw;
    }
  }
  return ServerPtr();
}
Exemplo n.º 2
0
static ServerPtr runServer() {
  for (s_server_port = PORT_MIN; s_server_port <= PORT_MAX; s_server_port++) {
    try {
      ServerPtr server = folly::make_unique<LibEventServer>(
          "127.0.0.1", s_server_port, 4);
      server->setRequestHandlerFactory<TestCurlRequestHandler>(0);
      server->start();
      return std::move(server);

    } catch (const FailedToListenException& e) {
      if (s_server_port == PORT_MAX) throw;
    }
  }
  return std::move(ServerPtr());
}
 RPCServer(SatelliteServerInfoPtr info) {
   m_server = ServerPtr(new RPCServerImpl(RuntimeOption::ServerIP, info));
 }
 DanglingPageServer(SatelliteServerInfoPtr info) {
   m_server = ServerPtr
     (new TypedServer<LibEventServer, HttpRequestHandler>
      (RuntimeOption::ServerIP, info->getPort(), info->getThreadCount(),
       info->getTimeoutSeconds()));
 }
Exemplo n.º 5
0
HttpServer::HttpServer()
  : m_stopped(false),
    m_loggerThread(this, &HttpServer::flushLog),
    m_watchDog(this, &HttpServer::watchDog) {

  // enabling mutex profiling, but it's not turned on
  LockProfiler::s_pfunc_profile = server_stats_log_mutex;

  if (RuntimeOption::TakeoverFilename.empty()) {
    m_pageServer = ServerPtr
      (new TypedServer<LibEventServer, HttpRequestHandler>
       (RuntimeOption::ServerIP, RuntimeOption::ServerPort,
        RuntimeOption::ServerThreadCount,
        RuntimeOption::RequestTimeoutSeconds));
  } else {
    LibEventServerWithTakeover* server =
      (new TypedServer<LibEventServerWithTakeover, HttpRequestHandler>
       (RuntimeOption::ServerIP, RuntimeOption::ServerPort,
        RuntimeOption::ServerThreadCount,
        RuntimeOption::RequestTimeoutSeconds));
    server->setTransferFilename(RuntimeOption::TakeoverFilename);
    server->addTakeoverListener(this);
    m_pageServer = ServerPtr(server);
  }

  m_adminServer = ServerPtr
    (new TypedServer<LibEventServer, AdminRequestHandler>
     (RuntimeOption::ServerIP, RuntimeOption::AdminServerPort,
      RuntimeOption::AdminThreadCount,
      RuntimeOption::RequestTimeoutSeconds));

  for (unsigned int i = 0; i < RuntimeOption::SatelliteServerInfos.size();
       i++) {
    SatelliteServerInfoPtr info = RuntimeOption::SatelliteServerInfos[i];
    SatelliteServerPtr satellite = SatelliteServer::Create(info);
    if (satellite) {
      if (info->getType() == SatelliteServer::KindOfDanglingPageServer) {
        m_danglings.push_back(satellite);
      } else {
        m_satellites.push_back(satellite);
      }
    }
  }

  if (RuntimeOption::EnableStaticContentCache) {
    StaticContentCache::TheCache.load();
  }
  ClassInfo::Load();
  SourceInfo::TheSourceInfo.load();
  RTTIInfo::TheRTTIInfo.init(true);

  hphp_process_init();
  apc_load(RuntimeOption::ApcLoadThread);

  Server::InstallStopSignalHandlers(m_pageServer);
  Server::InstallStopSignalHandlers(m_adminServer);

  if (!RuntimeOption::StartupDocument.empty()) {
    Hdf hdf;
    hdf["get"] = 1;
    hdf["url"] = RuntimeOption::StartupDocument;
    hdf["remote_host"] = RuntimeOption::ServerIP;

    ReplayTransport rt;
    rt.replayInput(hdf);
    HttpRequestHandler handler;
    handler.handleRequest(&rt);
    int code = rt.getResponseCode();
    if (code == 200) {
      Logger::Info("StartupDocument %s returned 200 OK: %s",
                   RuntimeOption::StartupDocument.c_str(),
                   rt.getResponse().c_str());
    } else {
      Logger::Error("StartupDocument %s failed %d: %s",
                    RuntimeOption::StartupDocument.c_str(),
                    code, rt.getResponse().data());
      return;
    }
  }

  for (unsigned int i = 0; i < RuntimeOption::ThreadDocuments.size(); i++) {
    ServiceThreadPtr thread
      (new ServiceThread(RuntimeOption::ThreadDocuments[i]));
    m_serviceThreads.push_back(thread);
  }
}