コード例 #1
0
ファイル: test_server.cpp プロジェクト: 2bj/hhvm
bool TestServer::TestHttpClient() {
  ServerPtr server;
  for (s_server_port = PORT_MIN; s_server_port <= PORT_MAX; s_server_port++) {
    try {
      server = ServerFactoryRegistry::createServer(
        m_serverType, "127.0.0.1", s_server_port, 50);
      server->setRequestHandlerFactory<EchoHandler>(0);
      server->start();
      break;
    } catch (const FailedToListenException& e) {
      if (s_server_port == PORT_MAX) throw;
    }
  }

  HeaderMap headers;
  headers["Cookie"].push_back("c1=v1;c2=v2;");
  headers["Cookie"].push_back("c3=v3;c4=v4;");
  string url = "http://127.0.0.1:" + lexical_cast<string>(s_server_port) +
    "/echo?name=value";

  static const StaticString s_Custom_colon_blah("Custom: blah");

  for (int i = 0; i < 10; i++) {
    HttpClient http;
    StringBuffer response;
    vector<String> responseHeaders;
    int code = http.get(url.c_str(), response, &headers, &responseHeaders);
    VS(code, 200);
    VS(response.data(),
       ("\nGET param: name = value"
        "\nHeader: Cookie"
        "\n0: c1=v1;c2=v2;"
        "\n1: c3=v3;c4=v4;"
        "\nHeader: Accept"
        "\n0: */*"
        "\nHeader: Host"
        "\n0: 127.0.0.1:" + lexical_cast<string>(s_server_port)).c_str());

    bool found = false;
    for (unsigned int i = 0; i < responseHeaders.size(); i++) {
      if (responseHeaders[i] == s_Custom_colon_blah) {
        found = true;
      }
    }
    VERIFY(found);
  }
  for (int i = 0; i < 10; i++) {
    HttpClient http;
    StringBuffer response;
    vector<String> responseHeaders;
    int code = http.post(url.c_str(), "postdata", 8, response, &headers,
                         &responseHeaders);
    VS(code, 200);
    VS(response.data(),
       ("\nGET param: name = value"
        "\nPOST data: postdata"
        "\nHeader: Content-Type"
        "\n0: application/x-www-form-urlencoded"
        "\nHeader: Cookie"
        "\n0: c1=v1;c2=v2;"
        "\n1: c3=v3;c4=v4;"
        "\nHeader: Accept"
        "\n0: */*"
        "\nHeader: Content-Length"
        "\n0: 8"
        "\nHeader: Host"
        "\n0: 127.0.0.1:" + lexical_cast<string>(s_server_port)).c_str());

    bool found = false;
    for (unsigned int i = 0; i < responseHeaders.size(); i++) {
      if (responseHeaders[i] == s_Custom_colon_blah) {
        found = true;
      }
    }
    VERIFY(found);
  }

  server->stop();
  server->waitForEnd();
  return Count(true);
}
コード例 #2
0
ファイル: UserDialog.cpp プロジェクト: DragonZX/flamerobin
bool UserPropertiesHandler::handleURI(URI& uri)
{
    bool addUser = uri.action == "add_user";
    bool editUser = uri.action == "edit_user";
    if (!addUser && !editUser)
        return false;

    wxWindow* w = getParentWindow(uri);
    ServerPtr server;
    UserPtr user;
    wxString title(_("Modify User"));
    if (addUser)
    {
        server = extractMetadataItemPtrFromURI<Server>(uri);
        if (!server)
            return true;
        title = _("Create New User");
        user.reset(new User(server));
    }
    else
    {
        user = extractMetadataItemPtrFromURI<User>(uri);
        if (!user)
            return true;
#ifdef __WXGTK__
        if (user->getUsername() == "SYSDBA")
        {
            showWarningDialog(w, _("The password for the SYSDBA user should not be changed here."),
                _("The appropriate way to change the password of the SYSDBA user is to run the changeDBAPassword.sh script in Firebird's bin directory.\n\nOtherwise the scripts will not be updated."),
                AdvancedMessageDialogButtonsOk(), config(), "DIALOG_warn_sysdba_change",
                _("Do not show this information again"));
        }
#endif
        server = user->getServer();
        if (!server)
            return true;
    }

    UserDialog d(w, title, addUser);
    d.setUser(user);
    if (d.ShowModal() == wxID_OK)
    {
        ProgressDialog pd(w, _("Connecting to Server..."), 1);
        pd.doShow();
        IBPP::Service svc;
        if (!getService(server.get(), svc, &pd, true)) // true = need SYSDBA password
            return true;

        try
        {
            IBPP::User u;
            user->assignTo(u);
            if (addUser)
                svc->AddUser(u);
            else
                svc->ModifyUser(u);
            server->notifyObservers();
        }
        catch(IBPP::Exception& e)
        {
            wxMessageBox(e.what(), _("Error"),
                wxOK | wxICON_WARNING);
        }
    }
    return true;
}
コード例 #3
0
ファイル: main.cpp プロジェクト: joelam789/esnetwork
int main()
{
    // print help
    PrintHelp();

#ifdef CLAY_SERVER

    // Create the work object, which will use clay library in thread's callback function
    WorkPtr claywork(new ClayWork());

    // Create the thread pool with minimum 128 threads
    WorkManagerPtr workmgr = CreateWorkManager(128);

    // Create the buffer pool with minimum 128 buffers, and every buffer will have 8192 bytes
    IoBufferManagerPtr bufmgr = CreateIoBufferManager(128, 8192);

    // Bind buffer pool to thread pool
    workmgr->SetBufferManager(bufmgr);

    // Create IO Handler with thread pool and the work object so that we can use multiple threads to handle requests
    IoHandlerPtr handler(new RequestMessageHandler(workmgr, claywork));

    // Create IO Filter to extract common messages (format: header + body)
    IoFilterPtr filter(new MessageCodec(32, 28, 4, 2 * 1024));

    // Create the server
    ServerPtr server = CreateServer();

    // Set IO Filter
    server->SetIoFilter(filter);

    // Set IO Handler
    server->SetIoHandler(handler);

    // Set memory pool
    server->SetIoBufferManager(bufmgr);

    // check for read idle, limit: 10 seconds
    //server->SetIdleTime(1, 10);

    // Start to listen
    bool svrok = server->Start(9098);

    if (svrok)
    {
        boost::thread input(HandleInput, server);
        input.join();
    }

    std::cout << std::endl << "--- END OF SERVER ---" << std::endl;

#elif defined(CLAY_CLIENT)

    // Create the work object, which will print the result string in thread's callback function
    WorkPtr displaywork(new DisplayWork());

    // Create the thread pool with minimum 32 threads
    WorkManagerPtr workmgr = CreateWorkManager(32);

    // Create the buffer pool with minimum 128 buffers, and every buffer will have 8192 bytes
    IoBufferManagerPtr bufmgr = CreateIoBufferManager(128, 8192);

    // Bind buffer pool to thread pool
    workmgr->SetBufferManager(bufmgr);

    // Create IO Handler with thread pool and the work object so that we can use multiple threads to handle responses
    IoHandlerPtr handler(new MessageHandler(workmgr, displaywork));

    // Create IO Filter to extract common messages (format: header + body)
    IoFilterPtr filter(new MessageCodec(32, 28, 4, 2 * 1024));

    // Create the client
    ClientPtr client = CreateClient();

    // Set IO Filter
    client->SetIoFilter(filter);

    // Set IO Handler
    client->SetIoHandler(handler);

    // Set memory pool
    client->SetIoBufferManager(bufmgr);

    // Other settings
    //client->SetConnectTimeOut(3); // set connect time out time: 3 seconds
    //client->SetIdleTime(2, 5); // check for write idle, limit: 5 seconds

    // Start to connect server
    bool cliok = client->Connect("localhost", 9098);

    if (cliok)
    {
        boost::thread input(HandleInput, client);
        input.join();
    }

    std::cout << std::endl << "--- END OF CLIENT ---" << std::endl;

#endif

    return 0;
}
コード例 #4
0
ファイル: loader.cpp プロジェクト: cstalder/Equalizer
void Loader::addDefaultObserver( ServerPtr server )
{
    AddObserverVisitor visitor;
    server->accept( visitor );
}
コード例 #5
0
ファイル: loader.cpp プロジェクト: cstalder/Equalizer
void Loader::addDestinationViews( ServerPtr server )
{
    AddDestinationViewVisitor visitor;
    server->accept( visitor );
}
コード例 #6
0
ファイル: loader.cpp プロジェクト: cstalder/Equalizer
void Loader::convertTo11( ServerPtr server )
{
    ConvertTo11Visitor visitor;
    server->accept( visitor );
}
コード例 #7
0
bool AdminRequestHandler::handleCheckRequest(const std::string &cmd,
                                             Transport *transport) {
  if (cmd == "check-load") {
    int count = HttpServer::Server->getPageServer()->getActiveWorker();
    transport->sendString(lexical_cast<string>(count));
    return true;
  }
  if (cmd == "check-ev") {
    int count =
      HttpServer::Server->getPageServer()->getLibEventConnectionCount();
    transport->sendString(lexical_cast<string>(count));
    return true;
  }
  if (cmd == "check-queued") {
    int count = HttpServer::Server->getPageServer()->getQueuedJobs();
    transport->sendString(lexical_cast<string>(count));
    return true;
  }
  if (cmd == "check-health") {
    std::stringstream out;
    bool first = true;
    out << "{" << endl;
    auto appendStat = [&](const char* name, int64_t value) {
       out << (!first ? "," : "") << "  \"" << name << "\":" << value << endl;
       first = false;
    };
    ServerPtr server = HttpServer::Server->getPageServer();
    appendStat("load", server->getActiveWorker());
    appendStat("queued", server->getQueuedJobs());
    Transl::Translator* tx = Transl::Translator::Get();
    appendStat("hhbc-roarena-capac", hhbc_arena_capacity());
    appendStat("tc-size", tx->getCodeSize());
    appendStat("tc-stubsize", tx->getStubSize());
    appendStat("targetcache", tx->getTargetCacheSize());
    appendStat("units", Eval::FileRepository::getLoadedFiles());
    out << "}" << endl;
    transport->sendString(out.str());
    return true;
  }
  if (cmd == "check-pl-load") {
    int count = PageletServer::GetActiveWorker();
    transport->sendString(lexical_cast<string>(count));
    return true;
  }
  if (cmd == "check-pl-queued") {
    int count = PageletServer::GetQueuedJobs();
    transport->sendString(lexical_cast<string>(count));
    return true;
  }
  if (cmd == "check-mem") {
    return toggle_switch(transport, RuntimeOption::CheckMemory);
  }
  if (cmd == "check-sql") {
    string stats = "<?xml version=\"1.0\" encoding=\"utf-8\"?>\n";
    stats += "<SQL>\n";
    stats += MySqlStats::ReportStats();
    stats += "</SQL>\n";
    transport->sendString(stats);
    return true;
  }
  return false;
}