Add file descriptor constructor for PipePosix.

llvm-svn: 236133
This commit is contained in:
Chaoren Lin 2015-04-29 17:36:58 +00:00
parent 3eb4b4589e
commit a52f48412d
3 changed files with 6 additions and 20 deletions

View File

@ -28,6 +28,7 @@ public:
static int kInvalidDescriptor;
PipePosix();
PipePosix(int read_fd, int write_fd);
~PipePosix() override;
@ -36,8 +37,6 @@ public:
Error
CreateNew(llvm::StringRef name, bool child_process_inherit) override;
Error
CreateWithFD(int read_fd, int write_fd);
Error
CreateWithUniqueName(llvm::StringRef prefix, bool child_process_inherit, llvm::SmallVectorImpl<char>& name) override;
Error
OpenAsReader(llvm::StringRef name, bool child_process_inherit) override;

View File

@ -129,10 +129,10 @@ SelectIO(int handle, bool is_read, const std::function<Error(bool&)> &io_handler
}
PipePosix::PipePosix()
{
m_fds[READ] = PipePosix::kInvalidDescriptor;
m_fds[WRITE] = PipePosix::kInvalidDescriptor;
}
: m_fds{PipePosix::kInvalidDescriptor, PipePosix::kInvalidDescriptor} {}
PipePosix::PipePosix(int read_fd, int write_fd)
: m_fds{read_fd, write_fd} {}
PipePosix::~PipePosix()
{
@ -186,15 +186,6 @@ PipePosix::CreateNew(llvm::StringRef name, bool child_process_inherit)
return error;
}
Error
PipePosix::CreateWithFD(int read_fd, int write_fd) {
if (CanRead() || CanWrite())
return Error("Pipe is already opened");
m_fds[READ] = read_fd;
m_fds[WRITE] = write_fd;
return Error();
}
Error
PipePosix::CreateWithUniqueName(llvm::StringRef prefix, bool child_process_inherit, llvm::SmallVectorImpl<char>& name)
{

View File

@ -344,11 +344,7 @@ writePortToPipe(const char *const named_pipe_path, const uint16_t port)
Error
writePortToPipe(int unnamed_pipe_fd, const uint16_t port)
{
Pipe port_pipe;
// Wait for 10 seconds for pipe to be opened.
auto error = port_pipe.CreateWithFD(Pipe::kInvalidDescriptor, unnamed_pipe_fd);
if (error.Fail())
return error;
Pipe port_pipe{Pipe::kInvalidDescriptor, unnamed_pipe_fd};
return WritePortToPipe(port_pipe, port);
}