5 #ifndef CVMFS_UTIL_PIPE_H_
6 #define CVMFS_UTIL_PIPE_H_
14 #include "gtest/gtest_prod.h"
18 #ifdef CVMFS_NAMESPACE_GUARD
19 namespace CVMFS_NAMESPACE_GUARD {
44 template <PipeType pipeType>
46 FRIEND_TEST(T_Util, ManagedExecRunShell);
47 FRIEND_TEST(T_Util, ManagedExecExecuteBinaryDoubleFork);
48 FRIEND_TEST(T_Util, ManagedExecExecuteBinaryAsChild);
66 fd_read_ = pipe_fd[0];
67 fd_write_ = pipe_fd[1];
113 const int num_bytes = write(fd_write_, &data,
sizeof(T));
114 return (num_bytes >= 0) && (
static_cast<size_t>(num_bytes) ==
sizeof(T));
138 bool Write(
const void *buf,
size_t nbyte) {
154 num_bytes = read(fd_read_, data,
sizeof(T));
155 }
while ((num_bytes < 0) && (errno == EINTR));
156 return (num_bytes >= 0) && (
static_cast<size_t>(num_bytes) ==
sizeof(T));
167 ReadPipe(fd_read_, data,
sizeof(T));
178 bool Read(
void *buf,
size_t nbyte) {
205 Pipe(
const int fd_read,
const int fd_write) : fd_read_(fd_read),
206 fd_write_(fd_write) {}
212 int retval = pipe(pipe_fd);
225 num_bytes = write(fd, buf, nbyte);
226 }
while ((num_bytes < 0) && (errno == EINTR));
227 if (!((num_bytes >= 0) && (static_cast<size_t>(num_bytes) == nbyte))) {
229 "WritePipe failed: expected write size %lu, "
230 "actually written %lu, errno %d, fd %d",
231 nbyte, num_bytes, errno, fd);
242 num_bytes = read(fd, buf, nbyte);
243 }
while ((num_bytes < 0) && (errno == EINTR));
244 if (!((num_bytes >= 0) && (static_cast<size_t>(num_bytes) == nbyte))) {
246 "ReadPipe failed: expected read size %lu, "
247 "actually read %lu, errno %d, fd %d",
248 nbyte, num_bytes, errno, fd);
253 #ifdef CVMFS_NAMESPACE_GUARD
257 #endif // CVMFS_UTIL_PIPE_H_
bool Write(const T &data)
void MakePipe(int pipe_fd[2])
bool Read(void *buf, size_t nbyte)
void WritePipe(int fd, const void *buf, size_t nbyte)
void ReadPipe(int fd, void *buf, size_t nbyte)
bool Write(const void *buf, size_t nbyte)
Pipe(const int fd_read, const int fd_write)
void MakePipe(int pipe_fd[2])
void WritePipe(int fd, const void *buf, size_t nbyte)
void ReadPipe(int fd, void *buf, size_t nbyte)
bool TryWrite(const T &data)