quic_simple_server_bin.cc 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. // Copyright 2014 The Chromium Authors. All rights reserved.
  2. // Use of this source code is governed by a BSD-style license that can be
  3. // found in the LICENSE file.
  4. // A binary wrapper for QuicServer. It listens forever on --port
  5. // (default 6121) until it's killed or ctrl-cd to death.
  6. #include <vector>
  7. #include "net/third_party/quiche/src/quiche/common/platform/api/quiche_command_line_flags.h"
  8. #include "net/third_party/quiche/src/quiche/common/platform/api/quiche_system_event_loop.h"
  9. #include "net/third_party/quiche/src/quiche/quic/core/quic_versions.h"
  10. #include "net/third_party/quiche/src/quiche/quic/platform/api/quic_flags.h"
  11. #include "net/third_party/quiche/src/quiche/quic/tools/quic_simple_server_backend.h"
  12. #include "net/third_party/quiche/src/quiche/quic/tools/quic_toy_server.h"
  13. #include "net/tools/quic/quic_simple_server.h"
  14. #include "net/tools/quic/quic_simple_server_backend_factory.h"
  15. class QuicSimpleServerFactory : public quic::QuicToyServer::ServerFactory {
  16. std::unique_ptr<quic::QuicSpdyServerBase> CreateServer(
  17. quic::QuicSimpleServerBackend* backend,
  18. std::unique_ptr<quic::ProofSource> proof_source,
  19. const quic::ParsedQuicVersionVector& supported_versions) override {
  20. return std::make_unique<net::QuicSimpleServer>(
  21. std::move(proof_source), config_,
  22. quic::QuicCryptoServerConfig::ConfigOptions(), supported_versions,
  23. backend);
  24. }
  25. private:
  26. quic::QuicConfig config_;
  27. };
  28. int main(int argc, char* argv[]) {
  29. quiche::QuicheSystemEventLoop event_loop("quic_server");
  30. const char* usage = "Usage: quic_server [options]";
  31. std::vector<std::string> non_option_args =
  32. quiche::QuicheParseCommandLineFlags(usage, argc, argv);
  33. if (!non_option_args.empty()) {
  34. quiche::QuichePrintCommandLineFlagHelp(usage);
  35. exit(0);
  36. }
  37. net::QuicSimpleServerBackendFactory backend_factory;
  38. QuicSimpleServerFactory server_factory;
  39. quic::QuicToyServer server(&backend_factory, &server_factory);
  40. return server.Start();
  41. }