Fix pipe reconnect

This commit is contained in:
badaix 2024-06-29 20:11:49 +02:00
parent 187ed109f0
commit a704fd11d5
2 changed files with 14 additions and 4 deletions

View file

@ -81,17 +81,17 @@ public:
inline double msRate() const
{
return (double)rate_ / 1000.;
return static_cast<double>(rate_) / 1000.;
}
inline double usRate() const
{
return (double)rate_ / 1000000.;
return static_cast<double>(rate_) / 1000000.;
}
inline double nsRate() const
{
return (double)rate_ / 1000000000.;
return static_cast<double>(rate_) / 1000000000.;
}
private:

View file

@ -27,6 +27,7 @@
// standard headers
#include <cerrno>
#include <memory>
#include <system_error>
using namespace std;
@ -59,7 +60,16 @@ void PipeStream::connect()
{
int fd = open(uri_.path.c_str(), O_RDONLY | O_NONBLOCK);
if (fd < 0)
throw SnapException("failed to open fifo \"" + uri_.path + "\": " + cpt::to_string(errno));
{
std::string error = "failed to open fifo \"" + uri_.path + "\": " + cpt::to_string(errno);
if (errno == static_cast<int>(std::errc::no_such_file_or_directory))
{
LOG(ERROR, LOG_TAG) << error << "\n";
wait(read_timer_, 200ms, [this] { connect(); });
return;
}
throw SnapException(error);
}
int pipe_size = -1;
#if !defined(MACOS) && !defined(FREEBSD)