Ejemplo n.º 1
0
void DebuggerServer::accept() {
  g_context.getCheck();
  TRACE(2, "DebuggerServer::accept\n");
  // Setup server-side usage logging before accepting any connections.
  Debugger::InitUsageLogging();
  // server loop
  unsigned int count = m_socks.size();
  struct pollfd* fds = (struct pollfd*)alloca(sizeof(struct pollfd) * count);

  for (unsigned int i = 0; i < count; i++) {
    fds[i].fd = nthSocket(i)->fd();
    fds[i].events = POLLIN|POLLERR|POLLHUP;
  }

  while (!m_stopped) {
    int ret = poll(fds, count, POLLING_SECONDS * 1000);
    for (unsigned int i = 0; ret > 0 && i < count; i++) {
      bool in = (fds[i].revents & POLLIN);
      if (in) {
        struct sockaddr sa;
        socklen_t salen = sizeof(sa);
        try {
          auto sock = nthSocket(i);
          auto new_sock = req::make<StreamSocket>(
            ::accept(sock->fd(), &sa, &salen), sock->getType());
          if (new_sock->valid()) {
            Debugger::CreateProxy(new_sock, false);
          } else {
            Logger::Error("unable to accept incoming debugger request");
          }
        } catch (Exception &e) {
          Logger::Error("%s", e.getMessage().c_str());
        } catch (std::exception &e) {
          Logger::Error("%s", e.what());
        } catch (...) {
          Logger::Error("(unknown exception was thrown)");
        }
      }

      fds[i].revents = 0; // reset the POLLIN flag
    } // else timed out, then we have a chance to check m_stopped bit

    // A chance for some housekeeping...
    Debugger::CleanupRetiredProxies();
  }

  for(auto &m_sock : m_socks) {
    m_sock.reset();
  }
  hphp_memory_cleanup();
}
Ejemplo n.º 2
0
  // implementing RequestHandler
  virtual void handleRequest(Transport *transport) {
    g_context.getCheck();
    transport->addHeader("ECHOED", transport->getHeader("ECHO").c_str());

    if (transport->getMethod() == Transport::Method::POST) {
      int len = 0;
      const void *data = transport->getPostData(len);
      String res = "POST: ";
      res += String((char*)data, len, CopyString);
      transport->sendString(res.c_str());
    } else {
      transport->sendString("OK");
    }
    hphp_memory_cleanup();
  }