diff options
author | Anton Samokhvalov <pg83@yandex.ru> | 2022-02-10 16:45:15 +0300 |
---|---|---|
committer | Daniil Cherednik <dcherednik@yandex-team.ru> | 2022-02-10 16:45:15 +0300 |
commit | 72cb13b4aff9bc9cf22e49251bc8fd143f82538f (patch) | |
tree | da2c34829458c7d4e74bdfbdf85dff449e9e7fb8 /util/stream/pipe.cpp | |
parent | 778e51ba091dc39e7b7fcab2b9cf4dbedfb6f2b5 (diff) | |
download | ydb-72cb13b4aff9bc9cf22e49251bc8fd143f82538f.tar.gz |
Restoring authorship annotation for Anton Samokhvalov <pg83@yandex.ru>. Commit 1 of 2.
Diffstat (limited to 'util/stream/pipe.cpp')
-rw-r--r-- | util/stream/pipe.cpp | 88 |
1 files changed, 44 insertions, 44 deletions
diff --git a/util/stream/pipe.cpp b/util/stream/pipe.cpp index 51be1934a7..1487182aa2 100644 --- a/util/stream/pipe.cpp +++ b/util/stream/pipe.cpp @@ -1,38 +1,38 @@ -#include "pipe.h" - -#include <util/generic/yexception.h> - -#include <cstdio> -#include <cerrno> - -class TPipeBase::TImpl { -public: +#include "pipe.h" + +#include <util/generic/yexception.h> + +#include <cstdio> +#include <cerrno> + +class TPipeBase::TImpl { +public: inline TImpl(const TString& command, const char* mode) : Pipe_(nullptr) - { + { #ifndef _freebsd_ - if (strcmp(mode, "r+") == 0) { - ythrow TSystemError(EINVAL) << "pipe \"r+\" mode is implemented only on FreeBSD"; - } + if (strcmp(mode, "r+") == 0) { + ythrow TSystemError(EINVAL) << "pipe \"r+\" mode is implemented only on FreeBSD"; + } #endif Pipe_ = ::popen(command.data(), mode); if (Pipe_ == nullptr) { ythrow TSystemError() << "failed to open pipe: " << command.Quote(); - } - } - + } + } + inline ~TImpl() { if (Pipe_ != nullptr) { - ::pclose(Pipe_); - } - } - -public: - FILE* Pipe_; -}; - + ::pclose(Pipe_); + } + } + +public: + FILE* Pipe_; +}; + TPipeBase::TPipeBase(const TString& command, const char* mode) - : Impl_(new TImpl(command, mode)) + : Impl_(new TImpl(command, mode)) { } @@ -45,20 +45,20 @@ TPipeInput::TPipeInput(const TString& command) size_t TPipeInput::DoRead(void* buf, size_t len) { if (Impl_->Pipe_ == nullptr) { - return 0; - } - - size_t bytesRead = ::fread(buf, 1, len, Impl_->Pipe_); - if (bytesRead == 0) { - int exitStatus = ::pclose(Impl_->Pipe_); + return 0; + } + + size_t bytesRead = ::fread(buf, 1, len, Impl_->Pipe_); + if (bytesRead == 0) { + int exitStatus = ::pclose(Impl_->Pipe_); Impl_->Pipe_ = nullptr; - if (exitStatus == -1) { - ythrow TSystemError() << "pclose() failed"; - } else if (exitStatus != 0) { - ythrow yexception() << "subprocess exited with non-zero status(" << exitStatus << ")"; - } - } - return bytesRead; + if (exitStatus == -1) { + ythrow TSystemError() << "pclose() failed"; + } else if (exitStatus != 0) { + ythrow yexception() << "subprocess exited with non-zero status(" << exitStatus << ")"; + } + } + return bytesRead; } TPipeOutput::TPipeOutput(const TString& command) @@ -68,8 +68,8 @@ TPipeOutput::TPipeOutput(const TString& command) void TPipeOutput::DoWrite(const void* buf, size_t len) { if (Impl_->Pipe_ == nullptr || len != ::fwrite(buf, 1, len, Impl_->Pipe_)) { - ythrow TSystemError() << "fwrite failed"; - } + ythrow TSystemError() << "fwrite failed"; + } } void TPipeOutput::Close() { @@ -88,9 +88,9 @@ TPipedBase::TPipedBase(PIPEHANDLE fd) } TPipedBase::~TPipedBase() { - if (Handle_.IsOpen()) { + if (Handle_.IsOpen()) { Handle_.Close(); - } + } } TPipedInput::TPipedInput(PIPEHANDLE fd) @@ -101,9 +101,9 @@ TPipedInput::TPipedInput(PIPEHANDLE fd) TPipedInput::~TPipedInput() = default; size_t TPipedInput::DoRead(void* buf, size_t len) { - if (!Handle_.IsOpen()) { + if (!Handle_.IsOpen()) { return 0; - } + } return Handle_.Read(buf, len); } |