Repository navigation
Expand file tree
/
Copy pathClientEmbeddedRunner.h
More file actions
57 lines (46 loc) · 1.79 KB
/
Copy pathClientEmbeddedRunner.h
File metadata and controls
57 lines (46 loc) · 1.79 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
#pragma once
#if defined(OS_LINUX)
#include <atomic>
#include <memory>
#include <Server/ClientEmbedded/ClientEmbedded.h>
#include <Server/ClientEmbedded/IClientDescriptorSet.h>
#include <Server/ClientEmbedded/PipeClientDescriptorSet.h>
#include <Server/ClientEmbedded/PtyClientDescriptorSet.h>
#include <Common/ThreadPool.h>
namespace DB
{
// Runs embedded client in dedicated thread, passes descriptors, checks its state
class ClientEmbeddedRunner
{
public:
explicit ClientEmbeddedRunner(
std::unique_ptr<IClientDescriptorSet> && client_descriptor_,
std::unique_ptr<Session> && database_session_)
: client_descriptors(std::move(client_descriptor_))
, db_session(std::move(database_session_))
, log(&Poco::Logger::get("ClientEmbeddedRunner"))
{
}
~ClientEmbeddedRunner();
bool hasStarted() const;
bool hasFinished() const;
int getExitCode() const;
IClientDescriptorSet::DescriptorSet getDescriptorsForServer();
void closeStdIn() const;
bool hasPty() const { return client_descriptors->isPty(); }
// Sets new window size for tty. Works only if IClientDescriptorSet is pty
void changeWindowSize(int width, int height, int width_pixels, int height_pixels);
void run(const NameToNameMap & envs, const String & starting_query = "");
private:
void clientRoutine(NameToNameMap envs, String starting_query);
// This is used by server thread and client thread, be sure that server only gets them via getDescriptorsForServer.
std::unique_ptr<IClientDescriptorSet> client_descriptors;
std::atomic_flag started = ATOMIC_FLAG_INIT;
std::atomic_flag finished = ATOMIC_FLAG_INIT;
ThreadFromGlobalPool client_thread;
std::unique_ptr<Session> db_session;
Poco::Logger * log;
int exit_code = 1;
};
}
#endif