diff options
author | vitalyisaev <vitalyisaev@ydb.tech> | 2023-11-30 13:26:22 +0300 |
---|---|---|
committer | vitalyisaev <vitalyisaev@ydb.tech> | 2023-11-30 15:44:45 +0300 |
commit | 0a98fece5a9b54f16afeb3a94b3eb3105e9c3962 (patch) | |
tree | 291d72dbd7e9865399f668c84d11ed86fb190bbf /library/cpp/streams | |
parent | cb2c8d75065e5b3c47094067cb4aa407d4813298 (diff) | |
download | ydb-0a98fece5a9b54f16afeb3a94b3eb3105e9c3962.tar.gz |
YQ Connector:Use docker-compose in integrational tests
Diffstat (limited to 'library/cpp/streams')
3 files changed, 74 insertions, 0 deletions
diff --git a/library/cpp/streams/growing_file_input/growing_file_input.cpp b/library/cpp/streams/growing_file_input/growing_file_input.cpp new file mode 100644 index 0000000000..0bbfa5ade9 --- /dev/null +++ b/library/cpp/streams/growing_file_input/growing_file_input.cpp @@ -0,0 +1,40 @@ +#include "growing_file_input.h" + +#include <util/datetime/base.h> +#include <util/generic/yexception.h> + +TGrowingFileInput::TGrowingFileInput(const TString& path) + : File_(path, OpenExisting | RdOnly | Seq) +{ + if (!File_.IsOpen()) { + ythrow TIoException() << "file " << path << " not open"; + } + + File_.Seek(0, sEnd); +} + +TGrowingFileInput::TGrowingFileInput(const TFile& file) + : File_(file) +{ + if (!File_.IsOpen()) { + ythrow TIoException() << "file (" << file.GetName() << ") not open"; + } + + File_.Seek(0, sEnd); +} + +size_t TGrowingFileInput::DoRead(void* buf, size_t len) { + for (int sleepTime = 1;;) { + size_t rr = File_.Read(buf, len); + + if (rr != 0) { + return rr; + } + + NanoSleep((ui64)sleepTime * 1000000); + + if (sleepTime < 2000) { + sleepTime <<= 1; + } + } +} diff --git a/library/cpp/streams/growing_file_input/growing_file_input.h b/library/cpp/streams/growing_file_input/growing_file_input.h new file mode 100644 index 0000000000..9054a5f3da --- /dev/null +++ b/library/cpp/streams/growing_file_input/growing_file_input.h @@ -0,0 +1,23 @@ +#pragma once + +#include <util/stream/input.h> +#include <util/system/file.h> + +/** + * Growing file input stream. + * + * File descriptor offsets to the end of the file, when the object is created. + * + * Read function waites for reading at least one byte. + */ +class TGrowingFileInput: public IInputStream { +public: + TGrowingFileInput(const TFile& file); + TGrowingFileInput(const TString& path); + +private: + size_t DoRead(void* buf, size_t len) override; + +private: + TFile File_; +}; diff --git a/library/cpp/streams/growing_file_input/ya.make b/library/cpp/streams/growing_file_input/ya.make new file mode 100644 index 0000000000..69c56fea46 --- /dev/null +++ b/library/cpp/streams/growing_file_input/ya.make @@ -0,0 +1,11 @@ +LIBRARY() + +SRCS( + growing_file_input.cpp +) + +END() + +RECURSE_FOR_TESTS( + ut +) |