Class: AngryShell::Shell::IPCState

Inherits:
Struct
  • Object
show all
Defined in:
lib/angry_shell.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeIPCState

Returns a new instance of IPCState.



103
104
105
# File 'lib/angry_shell.rb', line 103

def initialize
  super(IO.pipe, IO.pipe, IO.pipe, IO.pipe)
end

Instance Attribute Details

#errorObject Also known as: stderr

Returns the value of attribute error

Returns:

  • (Object)

    the current value of error



102
103
104
# File 'lib/angry_shell.rb', line 102

def error
  @error
end

#exceptionObject

Returns the value of attribute exception

Returns:

  • (Object)

    the current value of exception



102
103
104
# File 'lib/angry_shell.rb', line 102

def exception
  @exception
end

#readObject Also known as: stdout

Returns the value of attribute read

Returns:

  • (Object)

    the current value of read



102
103
104
# File 'lib/angry_shell.rb', line 102

def read
  @read
end

#writeObject

Returns the value of attribute write

Returns:

  • (Object)

    the current value of write



102
103
104
# File 'lib/angry_shell.rb', line 102

def write
  @write
end

Instance Method Details

#before_fork!Object



107
108
109
# File 'lib/angry_shell.rb', line 107

def before_fork!
  exception.last.fcntl(Fcntl::F_SETFD, Fcntl::FD_CLOEXEC)
end

#child_after_fork!Object



111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
# File 'lib/angry_shell.rb', line 111

def child_after_fork!
  write.last.close
  STDIN.reopen write.first
  write.first.close

  self.write = STDIN

  read.first.close
  STDOUT.reopen read.last
  read.last.close

  self.read = STDOUT

  error.first.close
  STDERR.reopen error.last
  error.last.close

  self.error = STDERR

  exception.first.close
  self.exception = exception.last

  STDOUT.sync = STDERR.sync = true
end

#close_allObject



148
149
150
# File 'lib/angry_shell.rb', line 148

def close_all
  [ read, write, error, exception ].flatten.compact.each {|fd| fd.close unless fd.closed?}
end

#parent_after_fork!Object



136
137
138
139
140
141
142
143
# File 'lib/angry_shell.rb', line 136

def parent_after_fork!
  [write.first, read.last, error.last, exception.last].each {|fd| fd.close}

  self.write = write.last
  self.read  = read.first
  self.error = error.first
  self.exception = exception.first
end