Class: ChattyProc::PipeServer
- Inherits:
-
Object
- Object
- ChattyProc::PipeServer
- Defined in:
- lib/chattyproc.rb
Instance Method Summary collapse
-
#callee! ⇒ Object
Public: Identifies the current process as the callee process.
-
#caller! ⇒ Object
Public: Identifies the current process as the caller process.
-
#initialize ⇒ PipeServer
constructor
Public: Sets up a new PipeServer.
-
#read ⇒ Object
Public: Reads a message from the appropriate pipe and unmarshalls it.
-
#write(message) ⇒ Object
Public: Writes a message to the appropriate pipe.
Constructor Details
#initialize ⇒ PipeServer
Public: Sets up a new PipeServer
7 8 9 10 11 12 13 14 |
# File 'lib/chattyproc.rb', line 7 def initialize @callee = [] @caller = [] @callee[0], @caller[1] = IO.pipe @caller[0], @callee[1] = IO.pipe @me = nil end |
Instance Method Details
#callee! ⇒ Object
Public: Identifies the current process as the callee process
17 18 19 20 21 22 23 |
# File 'lib/chattyproc.rb', line 17 def callee! @me = @callee @caller.each do |io| io.close end end |
#caller! ⇒ Object
Public: Identifies the current process as the caller process
26 27 28 29 30 31 32 |
# File 'lib/chattyproc.rb', line 26 def caller! @me = @caller @callee.each do |io| io.close end end |
#read ⇒ Object
Public: Reads a message from the appropriate pipe and unmarshalls it
42 43 44 45 46 47 48 |
# File 'lib/chattyproc.rb', line 42 def read = @me[0].gets return nil if .nil? Marshal.load(.unpack("m")[0]) end |
#write(message) ⇒ Object
Public: Writes a message to the appropriate pipe. The message can be anything that will Marshal cleanly.
36 37 38 39 |
# File 'lib/chattyproc.rb', line 36 def write() = [Marshal.dump()].pack("m0") @me[1].puts() end |