-
Notifications
You must be signed in to change notification settings - Fork 22
Expand file tree
/
Copy pathlive_connection.cpp
More file actions
50 lines (38 loc) · 1.64 KB
/
live_connection.cpp
File metadata and controls
50 lines (38 loc) · 1.64 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
#include "databento/detail/live_connection.hpp"
#include <memory>
#include "databento/detail/tcp_readable.hpp"
using databento::detail::LiveConnection;
LiveConnection::LiveConnection(ILogReceiver* log_receiver, const std::string& gateway,
std::uint16_t port)
: client_{log_receiver, gateway, port} {}
LiveConnection::LiveConnection(ILogReceiver* log_receiver, const std::string& gateway,
std::uint16_t port, TcpClient::RetryConf retry_conf)
: client_{log_receiver, gateway, port, retry_conf} {}
void LiveConnection::WriteAll(std::string_view str) { client_.WriteAll(str); }
void LiveConnection::WriteAll(const std::byte* buffer, std::size_t size) {
client_.WriteAll(buffer, size);
}
void LiveConnection::ReadExact(std::byte* buffer, std::size_t size) {
if (zstd_stream_) {
zstd_stream_->ReadExact(buffer, size);
} else {
client_.ReadExact(buffer, size);
}
}
databento::IReadable::Result LiveConnection::ReadSome(std::byte* buffer,
std::size_t max_size) {
return ReadSome(buffer, max_size, std::chrono::milliseconds{});
}
databento::IReadable::Result LiveConnection::ReadSome(
std::byte* buffer, std::size_t max_size, std::chrono::milliseconds timeout) {
if (zstd_stream_) {
return zstd_stream_->ReadSome(buffer, max_size, timeout);
}
return client_.ReadSome(buffer, max_size, timeout);
}
void LiveConnection::Close() { client_.Close(); }
void LiveConnection::SetCompression(Compression compression) {
if (compression == Compression::Zstd) {
zstd_stream_.emplace(std::make_unique<TcpReadable>(&client_));
}
}