diff options
author | mvel <mvel@yandex-team.ru> | 2022-02-10 16:45:41 +0300 |
---|---|---|
committer | Daniil Cherednik <dcherednik@yandex-team.ru> | 2022-02-10 16:45:41 +0300 |
commit | bd30392c4cc92487950adc375c07adf52da1d592 (patch) | |
tree | e8d1a3f19b7fc890bcef6e4cc5de41f1d88c9ac3 /library/cpp/http/server | |
parent | 5d50718e66d9c037dc587a0211110b7d25a66185 (diff) | |
download | ydb-bd30392c4cc92487950adc375c07adf52da1d592.tar.gz |
Restoring authorship annotation for <mvel@yandex-team.ru>. Commit 1 of 2.
Diffstat (limited to 'library/cpp/http/server')
-rw-r--r-- | library/cpp/http/server/http.cpp | 30 | ||||
-rw-r--r-- | library/cpp/http/server/http.h | 2 | ||||
-rw-r--r-- | library/cpp/http/server/http_ut.cpp | 102 | ||||
-rw-r--r-- | library/cpp/http/server/options.h | 14 | ||||
-rw-r--r-- | library/cpp/http/server/ya.make | 4 |
5 files changed, 76 insertions, 76 deletions
diff --git a/library/cpp/http/server/http.cpp b/library/cpp/http/server/http.cpp index 128583bdd70..6980ccd0351 100644 --- a/library/cpp/http/server/http.cpp +++ b/library/cpp/http/server/http.cpp @@ -8,7 +8,7 @@ #include <util/generic/intrlist.h> #include <util/generic/yexception.h> #include <util/network/address.h> -#include <util/network/socket.h> +#include <util/network/socket.h> #include <util/network/poller.h> #include <util/system/atomic.h> #include <util/system/compat.h> // stricmp, strnicmp, strlwr, strupr, stpcpy @@ -64,7 +64,7 @@ public: public: TSocket Socket_; NAddr::IRemoteAddrRef ListenerSockAddrRef_; - THttpServer::TImpl* HttpServ_ = nullptr; + THttpServer::TImpl* HttpServ_ = nullptr; bool Reject_ = false; TInstant LastUsed; TInstant AcceptMoment; @@ -131,7 +131,7 @@ public: public: TMutex Mutex_; TIntrusiveListWithAutoDelete<TClientConnection, TDelete> Conns_; - TSocketPoller* Poller_ = nullptr; + TSocketPoller* Poller_ = nullptr; const THttpServerOptions& Options; }; @@ -184,7 +184,7 @@ public: Poller.Reset(new TSocketPoller()); Connections.Reset(new TConnections(Poller.Get(), Options_)); - // Start the listener thread + // Start the listener thread ListenerRunningOK = false; // throws on error @@ -204,7 +204,7 @@ public: return false; } - // Wait until the thread has completely started and return the success indicator + // Wait until the thread has completely started and return the success indicator ListenStartEvent.Wait(); return ListenerRunningOK; @@ -271,15 +271,15 @@ public: } } } - + size_t GetRequestQueueSize() const { return Requests->Size(); } - + size_t GetFailQueueSize() const { return FailRequests->Size(); } - + const IThreadPool& GetRequestQueue() const { return *Requests; } @@ -316,7 +316,7 @@ public: private: TSocket S_; - TImpl* Server_ = nullptr; + TImpl* Server_ = nullptr; NAddr::IRemoteAddrRef SockAddrRef_; }; @@ -407,7 +407,7 @@ public: } TImpl(THttpServer* parent, ICallBack* cb, const TOptions& options, IThreadFactory* factory) - : TImpl( + : TImpl( parent, cb, MakeThreadPool<TSimpleThreadPool>(factory, options.UseElasticQueues, cb, options.RequestsThreadName), @@ -448,14 +448,14 @@ public: TSystemEvent ListenStartEvent; TMtpQueueRef Requests; TMtpQueueRef FailRequests; - TAtomic ConnectionCount = 0; + TAtomic ConnectionCount = 0; THolder<TSocketPoller> Poller; THolder<TConnections> Connections; - bool ListenerRunningOK = false; + bool ListenerRunningOK = false; int ErrorCode = 0; TOptions Options_; - ICallBack* Cb_ = nullptr; - THttpServer* Parent_ = nullptr; + ICallBack* Cb_ = nullptr; + THttpServer* Parent_ = nullptr; TWakeupPollAble WakeupPollAble; TMutex StopMutex; @@ -630,7 +630,7 @@ bool TClientRequest::Reply(void* /*ThreadSpecificResource*/) { } bool TClientRequest::IsLocal() const { - return HasLocalAddress(Socket()); + return HasLocalAddress(Socket()); } bool TClientRequest::CheckLoopback() { diff --git a/library/cpp/http/server/http.h b/library/cpp/http/server/http.h index b292d38f270..37a3dc61468 100644 --- a/library/cpp/http/server/http.h +++ b/library/cpp/http/server/http.h @@ -73,7 +73,7 @@ public: // shutdown a.s.a.p. void Stop(); - // graceful shutdown with serving all already open connections + // graceful shutdown with serving all already open connections void Shutdown(); void Wait(); diff --git a/library/cpp/http/server/http_ut.cpp b/library/cpp/http/server/http_ut.cpp index cc62bb988e7..64a62cc8891 100644 --- a/library/cpp/http/server/http_ut.cpp +++ b/library/cpp/http/server/http_ut.cpp @@ -36,7 +36,7 @@ Y_UNIT_TEST_SUITE(THttpServerTest) { } private: - TEchoServer* Parent_ = nullptr; + TEchoServer* Parent_ = nullptr; }; public: @@ -163,7 +163,7 @@ Y_UNIT_TEST_SUITE(THttpServerTest) { } TString Execute() { - TSocket* s = nullptr; + TSocket* s = nullptr; THolder<TSocket> singleReqSocket; if (KeepAliveConnection) { if (!KeepAlivedSocket) { @@ -277,48 +277,48 @@ Y_UNIT_TEST_SUITE(THttpServerTest) { } } - ui16 Port = 0; - bool UseHttpOutput = true; + ui16 Port = 0; + bool UseHttpOutput = true; TString Type = "GET"; TString ContentEncoding; TString Content; - bool KeepAliveConnection = false; + bool KeepAliveConnection = false; THolder<TSocket> KeepAlivedSocket; - bool EnableResponseEncoding = false; + bool EnableResponseEncoding = false; TString Hdr; bool Expect100Continue = false; }; class TFailingMtpQueue: public TSimpleThreadPool { - private: - bool FailOnAdd_ = false; + private: + bool FailOnAdd_ = false; - public: - void SetFailOnAdd(bool fail = true) { - FailOnAdd_ = fail; - } + public: + void SetFailOnAdd(bool fail = true) { + FailOnAdd_ = fail; + } [[nodiscard]] bool Add(IObjectInQueue* pObj) override { - if (FailOnAdd_) { - return false; - } - + if (FailOnAdd_) { + return false; + } + return TSimpleThreadPool::Add(pObj); - } - TFailingMtpQueue() = default; + } + TFailingMtpQueue() = default; TFailingMtpQueue(IThreadFactory* pool) : TSimpleThreadPool(pool) - { - } - }; - + { + } + }; + TString TestData(size_t size = 5 * 4096) { TString res; - for (size_t i = 0; i < size; ++i) { + for (size_t i = 0; i < size; ++i) { res += (char)i; } - return res; - } + return res; + } Y_UNIT_TEST(TestEchoServer) { TString res = TestData(); @@ -338,7 +338,7 @@ Y_UNIT_TEST_SUITE(THttpServerTest) { for (bool keepAlive : trueFalse) { r.KeepAliveConnection = keepAlive; - // THttpOutput use chunked stream, else use Content-Length + // THttpOutput use chunked stream, else use Content-Length for (bool useHttpOutput : trueFalse) { r.UseHttpOutput = useHttpOutput; @@ -367,7 +367,7 @@ Y_UNIT_TEST_SUITE(THttpServerTest) { server.Stop(); } } - + Y_UNIT_TEST(TestReusePortEnabled) { if (!IsReusePortAvailable()) { return; // skip test @@ -423,38 +423,38 @@ Y_UNIT_TEST_SUITE(THttpServerTest) { } Y_UNIT_TEST(TestFailServer) { - /** - * Emulate request processing failures - * Data should be large enough not to fit into socket buffer - **/ + /** + * Emulate request processing failures + * Data should be large enough not to fit into socket buffer + **/ TString res = TestData(10 * 1024 * 1024); TPortManager portManager; const ui16 port = portManager.GetPort(); - TEchoServer serverImpl(res); - THttpServer::TOptions options(port); - options.EnableKeepAlive(true); - options.EnableCompression(true); + TEchoServer serverImpl(res); + THttpServer::TOptions options(port); + options.EnableKeepAlive(true); + options.EnableCompression(true); using TFailingServerMtpQueue = TThreadPoolBinder<TFailingMtpQueue, THttpServer::ICallBack>; THttpServer::TMtpQueueRef mainWorkers = new TFailingServerMtpQueue(&serverImpl, SystemThreadFactory()); THttpServer::TMtpQueueRef failWorkers = new TThreadPool(SystemThreadFactory()); - THttpServer server(&serverImpl, mainWorkers, failWorkers, options); - - UNIT_ASSERT(server.Start()); - for (size_t i = 0; i < 3; ++i) { - // should fail on 2nd request - static_cast<TFailingMtpQueue*>(mainWorkers.Get())->SetFailOnAdd(i == 1); - TTestRequest r(port); - r.Content = res; - r.Type = "POST"; + THttpServer server(&serverImpl, mainWorkers, failWorkers, options); + + UNIT_ASSERT(server.Start()); + for (size_t i = 0; i < 3; ++i) { + // should fail on 2nd request + static_cast<TFailingMtpQueue*>(mainWorkers.Get())->SetFailOnAdd(i == 1); + TTestRequest r(port); + r.Content = res; + r.Type = "POST"; TString resp = r.Execute(); - if (i == 1) { + if (i == 1) { UNIT_ASSERT(resp.Contains("Service Unavailable")); - } else { - UNIT_ASSERT_C(resp == res, "diff echo response for request:\n" + r.GetDescription()); - } - } - server.Stop(); - } + } else { + UNIT_ASSERT_C(resp == res, "diff echo response for request:\n" + r.GetDescription()); + } + } + server.Stop(); + } class TReleaseConnectionServer: public THttpServer::ICallBack { class TRequest: public THttpClientRequestEx { diff --git a/library/cpp/http/server/options.h b/library/cpp/http/server/options.h index 38eda0e5e78..6ff69defd72 100644 --- a/library/cpp/http/server/options.h +++ b/library/cpp/http/server/options.h @@ -11,7 +11,7 @@ class THttpServerOptions { public: inline THttpServerOptions(ui16 port = 17000) noexcept - : Port(port) + : Port(port) { } @@ -146,8 +146,8 @@ public: typedef TVector<TAddr> TAddrs; - bool KeepAliveEnabled = true; - bool CompressionEnabled = false; + bool KeepAliveEnabled = true; + bool CompressionEnabled = false; bool RejectExcessConnections = false; bool ReusePort = false; // set SO_REUSEPORT socket option bool ReuseAddress = true; // set SO_REUSEADDR socket option @@ -157,10 +157,10 @@ public: const char* ServerName = "YWS/1.0"; // The Web server name to return in HTTP headers ui32 nThreads = 0; // Thread count for requests processing ui32 MaxQueueSize = 0; // Max allowed request count in queue - ui32 nFThreads = 1; - ui32 MaxFQueueSize = 0; - ui32 MaxConnections = 100; - int ListenBacklog = SOMAXCONN; + ui32 nFThreads = 1; + ui32 MaxFQueueSize = 0; + ui32 MaxConnections = 100; + int ListenBacklog = SOMAXCONN; TDuration ClientTimeout; size_t OutputBufferSize = 0; ui64 MaxInputContentLength = sizeof(size_t) <= 4 ? 2_GB : 64_GB; diff --git a/library/cpp/http/server/ya.make b/library/cpp/http/server/ya.make index bae6f33306b..a8cf9f2c0e5 100644 --- a/library/cpp/http/server/ya.make +++ b/library/cpp/http/server/ya.make @@ -2,8 +2,8 @@ LIBRARY() OWNER( pg - mvel - kulikov + mvel + kulikov g:base g:middle ) |