aboutsummaryrefslogtreecommitdiff
path: root/zenserver/projectstore.cpp
diff options
context:
space:
mode:
authorStefan Boberg <[email protected]>2022-06-13 14:35:14 +0200
committerStefan Boberg <[email protected]>2022-06-13 14:35:14 +0200
commitd1d44ce2fad29f2a68a3faf9f3b948b5e4c84912 (patch)
tree1ff5844702ce5ede1d3d74979f3c9e5039201d0a /zenserver/projectstore.cpp
parentMerge branch 'main' of https://github.com/EpicGames/zen (diff)
downloadzen-d1d44ce2fad29f2a68a3faf9f3b948b5e4c84912.tar.xz
zen-d1d44ce2fad29f2a68a3faf9f3b948b5e4c84912.zip
removed LocalProjectService prototype
Diffstat (limited to 'zenserver/projectstore.cpp')
-rw-r--r--zenserver/projectstore.cpp300
1 files changed, 0 insertions, 300 deletions
diff --git a/zenserver/projectstore.cpp b/zenserver/projectstore.cpp
index 7a55911da..1853941ed 100644
--- a/zenserver/projectstore.cpp
+++ b/zenserver/projectstore.cpp
@@ -1934,306 +1934,6 @@ HttpProjectService::HandleRequest(HttpServerRequest& Request)
}
}
-#if ZEN_USE_NAMED_PIPES
-
-//////////////////////////////////////////////////////////////////////////
-
-# if ZEN_PLATFORM_WINDOWS
-class SecurityAttributes
-{
-public:
- inline SECURITY_ATTRIBUTES* Attributes() { return &m_Attributes; }
-
-protected:
- SECURITY_ATTRIBUTES m_Attributes{};
- SECURITY_DESCRIPTOR m_Sd{};
-};
-
-// Security attributes which allows any user access
-
-class AnyUserSecurityAttributes : public SecurityAttributes
-{
-public:
- AnyUserSecurityAttributes()
- {
- m_Attributes.nLength = sizeof m_Attributes;
- m_Attributes.bInheritHandle = false; // Disable inheritance
-
- const BOOL success = InitializeSecurityDescriptor(&m_Sd, SECURITY_DESCRIPTOR_REVISION);
-
- if (success)
- {
- const BOOL bSetOk = SetSecurityDescriptorDacl(&m_Sd, TRUE, (PACL)NULL, FALSE);
- if (bSetOk)
- {
- m_Attributes.lpSecurityDescriptor = &m_Sd;
- }
- }
- }
-};
-# else
-struct AnyUserSecurityAttributes
-{
- int Attributes() { return 0666; }
-};
-# endif // ZEN_PLATFORM_WINDOWS
-
-//////////////////////////////////////////////////////////////////////////
-
-struct LocalProjectService::LocalProjectImpl
-{
- LocalProjectImpl() : m_WorkerThreadPool(ServiceThreadCount) {}
- ~LocalProjectImpl() { Stop(); }
-
- void Start()
- {
- ZEN_ASSERT(!m_IsStarted);
-
- for (int i = 0; i < 32; ++i)
- {
- PipeConnection* NewPipe = new PipeConnection(this);
- m_ServicePipes.push_back(NewPipe);
- m_IoContext.post([NewPipe] { NewPipe->Accept(); });
- }
-
- for (int i = 0; i < ServiceThreadCount; ++i)
- {
- asio::post(m_WorkerThreadPool, [this] {
- try
- {
- m_IoContext.run();
- }
- catch (std::exception& ex)
- {
- ZEN_ERROR("exception caught in pipe project service loop: {}", ex.what());
- }
-
- m_ShutdownLatch.count_down();
- });
- }
-
- m_IsStarted = true;
- }
-
- void Stop()
- {
- if (!m_IsStarted)
- {
- return;
- }
-
- for (PipeConnection* Pipe : m_ServicePipes)
- {
- Pipe->Disconnect();
- }
-
- m_IoContext.stop();
- m_ShutdownLatch.wait();
-
- for (PipeConnection* Pipe : m_ServicePipes)
- {
- delete Pipe;
- }
-
- m_ServicePipes.clear();
- }
-
-private:
- asio::io_context& IoContext() { return m_IoContext; }
- auto PipeSecurityAttributes() { return m_AnyUserSecurityAttributes.Attributes(); }
- static const int ServiceThreadCount = 4;
-
- std::latch m_ShutdownLatch{ServiceThreadCount};
- asio::thread_pool m_WorkerThreadPool;
- asio::io_context m_IoContext;
-
-# if ZEN_PLATFORM_WINDOWS
- class PipeConnection
- {
- enum PipeState
- {
- kUninitialized,
- kConnecting,
- kReading,
- kWriting,
- kDisconnected,
- kInvalid
- };
-
- LocalProjectImpl* m_Outer;
- asio::windows::stream_handle m_PipeHandle;
- std::atomic<PipeState> m_PipeState{kUninitialized};
-
- public:
- PipeConnection(LocalProjectImpl* Outer) : m_Outer(Outer), m_PipeHandle{m_Outer->IoContext()} {}
- ~PipeConnection() {}
-
- void Disconnect()
- {
- m_PipeState = kDisconnected;
- DisconnectNamedPipe(m_PipeHandle.native_handle());
- }
-
- void Accept()
- {
- StringBuilder<64> PipeName;
- PipeName << "\\\\.\\pipe\\zenprj"; // TODO: this should use an instance-specific identifier!
-
- HANDLE hPipe = CreateNamedPipeA(PipeName.c_str(),
- PIPE_ACCESS_DUPLEX | FILE_FLAG_OVERLAPPED,
- PIPE_TYPE_MESSAGE | PIPE_READMODE_MESSAGE | PIPE_WAIT,
- PIPE_UNLIMITED_INSTANCES, // Max instance count
- 65536, // Output buffer size
- 65536, // Input buffer size
- 10'000, // Default timeout (ms)
- m_Outer->PipeSecurityAttributes() // Security attributes
- );
-
- if (hPipe == INVALID_HANDLE_VALUE)
- {
- ZEN_WARN("failed while creating named pipe {}", PipeName.c_str());
-
- // TODO: error - how to best handle?
- }
-
- m_PipeHandle.assign(hPipe); // This now owns the handle and will close it
-
- m_PipeState = kConnecting;
-
- asio::windows::overlapped_ptr OverlappedPtr(
- m_PipeHandle.get_executor(),
- std::bind(&PipeConnection::OnClientConnect, this, std::placeholders::_1, std::placeholders::_2));
-
- OVERLAPPED* Overlapped = OverlappedPtr.get();
- BOOL Ok = ConnectNamedPipe(hPipe, Overlapped);
- DWORD LastError = GetLastError();
-
- if (!Ok && LastError != ERROR_IO_PENDING)
- {
- m_PipeState = kInvalid;
-
- // The operation completed immediately, so a completion notification needs
- // to be posted. When complete() is called, ownership of the OVERLAPPED-
- // derived object passes to the io_service.
- std::error_code Ec(LastError, asio::error::get_system_category());
- OverlappedPtr.complete(Ec, 0);
- }
- else
- {
- // The operation was successfully initiated, so ownership of the
- // OVERLAPPED-derived object has now passed to the io_service.
- OverlappedPtr.release();
- }
- }
-
- private:
- void OnClientConnect(const std::error_code& Ec, size_t BytesTransferred)
- {
- ZEN_UNUSED(BytesTransferred);
-
- if (Ec)
- {
- if (m_PipeState == kDisconnected)
- {
- return;
- }
-
- ZEN_WARN("pipe connection error: {}", Ec.message());
-
- // TODO: should disconnect and issue a new connect
- return;
- }
-
- ZEN_DEBUG("pipe connection established");
-
- IssueRead();
- }
-
- void IssueRead()
- {
- m_PipeState = kReading;
-
- m_PipeHandle.async_read_some(asio::mutable_buffer(m_MsgBuffer, sizeof m_MsgBuffer),
- std::bind(&PipeConnection::OnClientRead, this, std::placeholders::_1, std::placeholders::_2));
- }
-
- void OnClientRead(const std::error_code& Ec, size_t Bytes)
- {
- if (Ec)
- {
- if (m_PipeState == kDisconnected)
- {
- return;
- }
-
- ZEN_WARN("pipe read error: {}", Ec.message());
-
- // TODO: should disconnect and issue a new connect
- return;
- }
-
- ZEN_DEBUG("received message: {} bytes", Bytes);
-
- // TODO: Actually process request
-
- m_PipeState = kWriting;
-
- asio::async_write(m_PipeHandle,
- asio::buffer(m_MsgBuffer, Bytes),
- std::bind(&PipeConnection::OnWriteCompletion, this, std::placeholders::_1, std::placeholders::_2));
- }
-
- void OnWriteCompletion(const std::error_code& Ec, size_t Bytes)
- {
- ZEN_UNUSED(Bytes);
-
- if (Ec)
- {
- if (m_PipeState == kDisconnected)
- {
- return;
- }
-
- ZEN_WARN("pipe write error: {}", Ec.message());
-
- // TODO: should disconnect and issue a new connect
- return;
- }
-
- // Go back to reading
- IssueRead();
- }
-
- uint8_t m_MsgBuffer[16384];
- };
-# else
- class PipeConnection
- {
- public:
- PipeConnection(LocalProjectImpl*) {}
- void Accept() {}
- void Disconnect() {}
- };
-# endif
-
- AnyUserSecurityAttributes m_AnyUserSecurityAttributes;
- std::vector<PipeConnection*> m_ServicePipes;
- bool m_IsStarted = false;
-};
-
-LocalProjectService::LocalProjectService(CasStore& Store, ProjectStore* Projects) : m_CasStore(Store), m_ProjectStore(Projects)
-{
- m_Impl = std::make_unique<LocalProjectImpl>();
- m_Impl->Start();
-}
-
-LocalProjectService::~LocalProjectService()
-{
- m_Impl->Stop();
-}
-
-#endif
-
//////////////////////////////////////////////////////////////////////////
#if ZEN_WITH_TESTS