Class: TConsole::PipeServer
- Inherits:
-
Object
- Object
- TConsole::PipeServer
- Defined in:
- lib/tconsole/pipe_server.rb
Instance Method Summary collapse
-
#callee! ⇒ Object
Identifies the current process as the callee process.
-
#caller! ⇒ Object
Identifies the current process as the caller process.
-
#initialize ⇒ PipeServer
constructor
A new instance of PipeServer.
-
#read ⇒ Object
Reads a message from the appropriate pipe and unmarshalls it.
-
#write(message) ⇒ Object
Writes a message to the appropriate pipe.
Constructor Details
#initialize ⇒ PipeServer
Returns a new instance of PipeServer.
4 5 6 7 8 9 10 11 |
# File 'lib/tconsole/pipe_server.rb', line 4 def initialize @callee = [] @caller = [] @callee[0], @caller[1] = IO.pipe @caller[0], @callee[1] = IO.pipe @me = nil end |
Instance Method Details
#callee! ⇒ Object
Identifies the current process as the callee process
14 15 16 17 18 19 20 |
# File 'lib/tconsole/pipe_server.rb', line 14 def callee! @me = @callee @caller.each do |io| io.close end end |
#caller! ⇒ Object
Identifies the current process as the caller process
23 24 25 26 27 28 29 |
# File 'lib/tconsole/pipe_server.rb', line 23 def caller! @me = @caller @callee.each do |io| io.close end end |
#read ⇒ Object
Reads a message from the appropriate pipe and unmarshalls it
39 40 41 42 43 44 45 |
# File 'lib/tconsole/pipe_server.rb', line 39 def read = @me[0].gets return nil if .nil? Marshal.load(.unpack("m")[0]) end |
#write(message) ⇒ Object
Writes a message to the appropriate pipe. The message can be anything that will Marshal cleanly
33 34 35 36 |
# File 'lib/tconsole/pipe_server.rb', line 33 def write() = [Marshal.dump()].pack("m0") @me[1].puts() end |