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];
111 const int num_bytes = write(fd_write_, &data,
sizeof(T));
112 return (num_bytes >= 0) && (
static_cast<size_t>(num_bytes) ==
sizeof(T));
136 bool Write(
const void *buf,
size_t nbyte) {
152 num_bytes = read(fd_read_, data,
sizeof(T));
153 }
while ((num_bytes < 0) && (errno == EINTR));
154 return (num_bytes >= 0) && (
static_cast<size_t>(num_bytes) ==
sizeof(T));
165 ReadPipe(fd_read_, data,
sizeof(T));
176 bool Read(
void *buf,
size_t nbyte) {
199 Pipe(
const int fd_read,
const int fd_write)
200 : fd_read_(fd_read), fd_write_(fd_write) { }
206 const int retval = pipe(pipe_fd);
219 num_bytes = write(fd, buf, nbyte);
220 }
while ((num_bytes < 0) && (errno == EINTR));
221 if (!((num_bytes >= 0) && (static_cast<size_t>(num_bytes) == nbyte))) {
223 "WritePipe failed: expected write size %lu, "
224 "actually written %lu, errno %d, fd %d",
225 nbyte, num_bytes, errno, fd);
236 num_bytes = read(fd, buf, nbyte);
237 }
while ((num_bytes < 0) && (errno == EINTR));
238 if (!((num_bytes >= 0) && (static_cast<size_t>(num_bytes) == nbyte))) {
240 "ReadPipe failed: expected read size %lu, "
241 "actually read %lu, errno %d, fd %d",
242 nbyte, num_bytes, errno, fd);
247 #ifdef CVMFS_NAMESPACE_GUARD
251 #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)