|
| 1 | +// Copyright 2024, Roman Gershman. All rights reserved. |
| 2 | +// See LICENSE for licensing terms. |
| 3 | + |
| 4 | +#include "base/flags.h" |
| 5 | +#include "base/init.h" |
| 6 | +#include "base/logging.h" |
| 7 | +#include "util/cloud/gcp/gcs.h" |
| 8 | +#include "util/fibers/pool.h" |
| 9 | + |
| 10 | +using namespace std; |
| 11 | +using namespace boost; |
| 12 | +using namespace util; |
| 13 | + |
| 14 | +using absl::GetFlag; |
| 15 | + |
| 16 | +ABSL_FLAG(string, bucket, "", ""); |
| 17 | +ABSL_FLAG(string, access_token, "", ""); |
| 18 | +ABSL_FLAG(uint32_t, connect_ms, 2000, ""); |
| 19 | +ABSL_FLAG(bool, epoll, false, "Whether to use epoll instead of io_uring"); |
| 20 | + |
| 21 | + |
| 22 | +void Run(SSL_CTX* ctx) { |
| 23 | + fb2::ProactorBase* pb = fb2::ProactorBase::me(); |
| 24 | + cloud::GCS gcs(ctx, pb); |
| 25 | + error_code ec = gcs.Connect(GetFlag(FLAGS_connect_ms)); |
| 26 | + CHECK(!ec) << "Could not connect " << ec; |
| 27 | + auto res = gcs.ListBuckets(); |
| 28 | + CHECK(res) << res.error(); |
| 29 | + for (auto v : *res) { |
| 30 | + CONSOLE_INFO << v; |
| 31 | + } |
| 32 | +} |
| 33 | + |
| 34 | +int main(int argc, char** argv) { |
| 35 | + MainInitGuard guard(&argc, &argv); |
| 36 | + |
| 37 | + std::unique_ptr<util::ProactorPool> pp; |
| 38 | + |
| 39 | +#ifdef __linux__ |
| 40 | + if (absl::GetFlag(FLAGS_epoll)) { |
| 41 | + pp.reset(util::fb2::Pool::Epoll()); |
| 42 | + } else { |
| 43 | + pp.reset(util::fb2::Pool::IOUring(256)); |
| 44 | + } |
| 45 | +#else |
| 46 | + pp.reset(util::fb2::Pool::Epoll()); |
| 47 | +#endif |
| 48 | + |
| 49 | + pp->Run(); |
| 50 | + |
| 51 | + SSL_CTX* ctx = util::http::TlsClient::CreateSslContext(); |
| 52 | + pp->GetNextProactor()->Await([ctx] { |
| 53 | + Run(ctx); |
| 54 | + }); |
| 55 | + util::http::TlsClient::FreeContext(ctx); |
| 56 | + |
| 57 | + |
| 58 | + return 0; |
| 59 | +} |
0 commit comments