Repository navigation
Expand file tree
/
Copy pathPtyClientDescriptorSet.h
More file actions
67 lines (51 loc) · 1.96 KB
/
Copy pathPtyClientDescriptorSet.h
File metadata and controls
67 lines (51 loc) · 1.96 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
58
59
60
61
62
63
64
65
66
67
#pragma once
#if defined(OS_LINUX)
#include <Server/ClientEmbedded/IClientDescriptorSet.h>
#include <boost/iostreams/device/file_descriptor.hpp>
#include <boost/iostreams/stream.hpp>
#include <Poco/Pipe.h>
#include <base/types.h>
namespace DB
{
class PtyClientDescriptorSet : public IClientDescriptorSet
{
public:
PtyClientDescriptorSet(const String & term_name, int width, int height, int width_pixels, int height_pixels);
~PtyClientDescriptorSet() override;
DescriptorSet getDescriptorsForClient() override
{
return DescriptorSet{.in = pty_slave.get(), .out = pty_slave.get(), .err = pty_slave.get()};
}
DescriptorSet getDescriptorsForServer() override { return DescriptorSet{.in = pty_master.get(), .out = pty_master.get(), .err = -1}; }
StreamSet getStreamsForClient() override { return StreamSet{.in = input_stream, .out = output_stream, .err = output_stream}; }
void changeWindowSize(int width, int height, int width_pixels, int height_pixels) const;
void closeServerDescriptors() override { pty_master.close(); }
void closeStdIn() override {}
bool isPty() const override { return true; }
private:
class FileDescriptorWrapper
{
public:
FileDescriptorWrapper() = default;
void capture(int fd_)
{
close();
fd = fd_;
}
int get() const { return fd; }
void close();
~FileDescriptorWrapper() { close(); } // may throw, thus std::terminate
private:
int fd = -1;
};
String term_name;
FileDescriptorWrapper pty_master;
FileDescriptorWrapper pty_slave;
// Provide streams on top of file descriptors
boost::iostreams::file_descriptor_source fd_source; // handles pty_slave lifetime
boost::iostreams::file_descriptor_sink fd_sink;
boost::iostreams::stream<boost::iostreams::file_descriptor_source> input_stream;
boost::iostreams::stream<boost::iostreams::file_descriptor_sink> output_stream;
};
}
#endif