Make is_input a member of io_pipe_t

This commit is contained in:
Cheer Xiao 2013-01-16 11:55:57 +08:00
parent a63c0311bb
commit 57ef5289fe
4 changed files with 34 additions and 34 deletions

View file

@ -571,7 +571,10 @@ void exec(parser_t &parser, job_t *j)
{
shared_ptr<io_data_t> &io = j->io.at(idx);
if ((io->io_mode == IO_BUFFER) && io->is_input)
if ((io->io_mode == IO_BUFFER))
{
CAST_INIT(io_buffer_t *, io_buffer, io.get());
if (io_buffer->is_input)
{
/*
Input redirection - create a new gobetween process to take
@ -583,10 +586,11 @@ void exec(parser_t &parser, job_t *j)
j->first_process->pipe_read_fd = io->fd;
fake->next = j->first_process;
j->first_process = fake;
input_redirect = static_cast<const io_buffer_t *>(io.get());
input_redirect = io_buffer;
break;
}
}
}
if (j->first_process->type==INTERNAL_EXEC)
{
@ -615,12 +619,10 @@ void exec(parser_t &parser, job_t *j)
}
shared_ptr<io_pipe_t> pipe_read(new io_pipe_t(0));
pipe_read->is_input = 1;
shared_ptr<io_pipe_t> pipe_read(new io_pipe_t(0, true));
pipe_read->pipe_fd[0] = pipe_read->pipe_fd[1] = -1;
shared_ptr<io_pipe_t> pipe_write(new io_pipe_t(1));
pipe_write->is_input = 0;
shared_ptr<io_pipe_t> pipe_write(new io_pipe_t(1, false));
pipe_write->pipe_fd[0] = pipe_write->pipe_fd[1] = -1;
j->io.push_back(pipe_write);

11
io.cpp
View file

@ -72,12 +72,14 @@ void io_file_t::print() const
void io_pipe_t::print() const
{
fprintf(stderr, "pipe {%d, %d}\n", pipe_fd[0], pipe_fd[1]);
fprintf(stderr, "pipe {%d, %d} (input: %s)\n", pipe_fd[0], pipe_fd[1],
is_input ? "yes" : "no");
}
void io_buffer_t::print() const
{
fprintf(stderr, "buffer %p (size %lu)\n", out_buffer_ptr(), out_buffer_size());
fprintf(stderr, "buffer %p (input: %s, size %lu)\n", out_buffer_ptr(),
is_input ? "yes" : "no", out_buffer_size());
}
void io_buffer_t::read()
@ -132,8 +134,7 @@ void io_buffer_t::read()
io_buffer_t *io_buffer_t::create(bool is_input)
{
bool success = true;
io_buffer_t *buffer_redirect = new io_buffer_t(is_input ? 0 : 1);
buffer_redirect->is_input = is_input ? true : false;
io_buffer_t *buffer_redirect = new io_buffer_t(is_input ? 0 : 1, is_input);
if (exec_pipe(buffer_redirect->pipe_fd) == -1)
{
@ -221,7 +222,7 @@ void io_print(const io_chain_t &chain)
for (size_t i=0; i < chain.size(); i++)
{
const shared_ptr<const io_data_t> &io = chain.at(i);
fprintf(stderr, "\t%lu: fd:%d, input:%s, ", (unsigned long)i, io->fd, io->is_input ? "yes" : "no");
fprintf(stderr, "\t%lu: fd:%d, ", (unsigned long)i, io->fd);
io->print();
}
}

17
io.h
View file

@ -24,8 +24,7 @@ private:
protected:
io_data_t(io_mode_t m, int f) :
io_mode(m),
fd(f),
is_input(0)
fd(f)
{
}
@ -36,10 +35,6 @@ public:
int fd;
virtual void print() const = 0;
/** Set to true if this is an input io redirection */
bool is_input;
virtual ~io_data_t() = 0;
};
@ -106,12 +101,14 @@ class io_pipe_t : public io_data_t
{
public:
int pipe_fd[2];
bool is_input;
virtual void print() const;
io_pipe_t(int f):
io_pipe_t(int f, bool i):
io_data_t(IO_PIPE, f),
pipe_fd()
pipe_fd(),
is_input(i)
{
}
};
@ -122,8 +119,8 @@ private:
/** buffer to save output in */
std::vector<char> *out_buffer;
io_buffer_t(int f):
io_pipe_t(f),
io_buffer_t(int f, bool i):
io_pipe_t(f, i),
out_buffer(new std::vector<char>)
{
io_mode = IO_BUFFER;

View file

@ -248,7 +248,7 @@ static int handle_child_io(io_chain_t &io_chain)
{
CAST_INIT(io_pipe_t *, io_pipe, io);
/* If write_pipe_idx is 0, it means we're connecting to the read end (first pipe fd). If it's 1, we're connecting to the write end (second pipe fd). */
unsigned int write_pipe_idx = (io->is_input ? 0 : 1);
unsigned int write_pipe_idx = (io_pipe->is_input ? 0 : 1);
/*
debug( 0,
L"%ls %ls on fd %d (%d %d)",
@ -488,7 +488,7 @@ bool fork_actions_make_spawn_properties(posix_spawnattr_t *attr, posix_spawn_fil
case IO_PIPE:
{
CAST_INIT(const io_pipe_t *, io_pipe, io.get());
unsigned int write_pipe_idx = (io->is_input ? 0 : 1);
unsigned int write_pipe_idx = (io_pipe->is_input ? 0 : 1);
int from_fd = io_pipe->pipe_fd[write_pipe_idx];
int to_fd = io->fd;
if (! err)