Go to the documentation of this file.
18 #include <sys/types.h>
36 if (!CreatePipe(&hRead, &hWrite,
nullptr, 0))
44 if (::pipe(fds))
THROW_EXCEPTION(
"Unix error creating pipe endpoints!");
53 : timeout_read_start_us(0), timeout_read_between_us(0), m_pipe_file(0)
94 catch (std::invalid_argument&)
127 if (!ReadFile((HANDLE)
m_pipe_file, Buffer, Count, &nActuallyRead,
nullptr))
130 return static_cast<size_t>(nActuallyRead);
141 size_t alreadyRead = 0;
142 bool timeoutExpired =
false;
144 struct timeval timeoutSelect;
145 struct timeval* ptrTimeout;
153 while (alreadyRead < Count && !timeoutExpired)
156 unsigned int curTimeout_us = alreadyRead == 0
160 if (curTimeout_us == 0)
161 ptrTimeout =
nullptr;
164 timeoutSelect.tv_sec = curTimeout_us / 1000000;
165 timeoutSelect.tv_usec = (curTimeout_us % 1000000);
166 ptrTimeout = &timeoutSelect;
178 timeoutExpired =
true;
183 const size_t remainToRead = Count - alreadyRead;
186 const size_t readNow = ::read(
190 if (readNow !=
static_cast<size_t>(-1))
193 alreadyRead += readNow;
201 if (readNow == 0 && remainToRead != 0)
206 timeoutExpired =
true;
225 DWORD nActuallyWritten;
227 (HANDLE)
m_pipe_file, Buffer, Count, &nActuallyWritten,
nullptr))
230 return static_cast<size_t>(nActuallyWritten);
TSeekOrigin
Used in CStream::Seek.
unsigned int timeout_read_start_us
(Default=0) Timeout for read operations: microseconds (us) to wait for the first byte.
std::string serialize()
Converts the end-point into a string suitable for reconstruction at a child process.
void close()
Closes the pipe (normally not needed to be called by users, automatically done at destructor)
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.
virtual uint64_t Seek(int64_t of, CStream::TSeekOrigin o=sFromBeginning) override
Without effect in this class.
#define THROW_EXCEPTION(msg)
Common interface of read & write pipe end-points.
unsigned int timeout_read_between_us
(Default=0) Timeout between burst reads operations: microseconds (us) to wait between two partial rea...
unsigned __int64 uint64_t
virtual ~CPipeBaseEndPoint()
static void initializePipe(CPipeReadEndPoint &outReadPipe, CPipeWriteEndPoint &outWritePipe)
Creates a new pipe and returns the read & write end-points as newly allocated objects.
#define ASSERTMSG_(f, __ERROR_MSG)
Defines an assertion mechanism.
The write end-point in a pipe created with mrpt::synch::CPipe.
virtual uint64_t getPosition() const override
Without effect in this class.
GLsizei const GLchar ** string
virtual size_t Read(void *Buffer, size_t Count) override
Introduces a pure virtual method responsible for reading from the stream.
virtual size_t Write(const void *Buffer, size_t Count) override
Introduces a pure virtual method responsible for writing to the stream.
virtual uint64_t getTotalBytesCount() const override
Without effect in this class.
Page generated by Doxygen 1.8.17 for MRPT 1.9.9 Git: ad3a9d8ae Tue May 1 23:10:22 2018 -0700 at miƩ 12 jul 2023 10:03:34 CEST | |