18 #include <sys/types.h> 36 if (!CreatePipe(&hRead, &hWrite,
nullptr, 0))
44 if (::pipe(fds))
THROW_EXCEPTION(
"Unix error creating pipe endpoints!");
91 catch (std::invalid_argument&)
124 if (!ReadFile((HANDLE)
m_pipe_file, Buffer, Count, &nActuallyRead,
nullptr))
127 return static_cast<size_t>(nActuallyRead);
138 size_t alreadyRead = 0;
139 bool timeoutExpired =
false;
141 struct timeval timeoutSelect
144 struct timeval* ptrTimeout{
nullptr};
152 while (alreadyRead < Count && !timeoutExpired)
155 unsigned int curTimeout_us = alreadyRead == 0
159 if (curTimeout_us == 0)
160 ptrTimeout =
nullptr;
163 timeoutSelect.tv_sec = curTimeout_us / 1000000;
164 timeoutSelect.tv_usec = (curTimeout_us % 1000000);
165 ptrTimeout = &timeoutSelect;
177 timeoutExpired =
true;
182 const size_t remainToRead = Count - alreadyRead;
185 const size_t readNow = ::read(
189 if (readNow != static_cast<size_t>(-1))
192 alreadyRead += readNow;
200 if (readNow == 0 && remainToRead != 0)
205 timeoutExpired =
true;
224 DWORD nActuallyWritten;
226 (HANDLE)
m_pipe_file, Buffer, Count, &nActuallyWritten,
nullptr))
229 return static_cast<size_t>(nActuallyWritten);
TSeekOrigin
Used in CStream::Seek.
size_t Read(void *Buffer, size_t Count) override
Introduces a pure virtual method responsible for reading from the stream.
#define THROW_EXCEPTION(msg)
uint64_t getPosition() const override
Without effect in this class.
void close()
Closes the pipe (normally not needed to be called by users, automatically done at destructor) ...
size_t Write(const void *Buffer, size_t Count) override
Introduces a pure virtual method responsible for writing to the stream.
std::string serialize()
Converts the end-point into a string suitable for reconstruction at a child process.
uint64_t Seek(int64_t of, CStream::TSeekOrigin o=sFromBeginning) override
Without effect in this class.
#define ASSERTMSG_(f, __ERROR_MSG)
Defines an assertion mechanism.
GLsizei const GLchar ** string
The write end-point in a pipe created with mrpt::synch::CPipe.
~CPipeBaseEndPoint() override
unsigned __int64 uint64_t
unsigned int timeout_read_start_us
(Default=0) Timeout for read operations: microseconds (us) to wait for the first byte.
uint64_t getTotalBytesCount() const override
Without effect in this class.
The read end-point in a pipe created with mrpt::synch::CPipe.
std::string std::string to_string(T v)
Just like std::to_string(), but with an overloaded version for std::string arguments.
unsigned int timeout_read_between_us
(Default=0) Timeout between burst reads operations: microseconds (us) to wait between two partial rea...
static void initializePipe(CPipeReadEndPoint &outReadPipe, CPipeWriteEndPoint &outWritePipe)
Creates a new pipe and returns the read & write end-points as newly allocated objects.
Common interface of read & write pipe end-points.