Class: Hermeneutics::Cli::Protocol
- Inherits:
-
Object
- Object
- Hermeneutics::Cli::Protocol
- Defined in:
- lib/hermeneutics/cli/protocol.rb
Defined Under Namespace
Constant Summary collapse
- CRLF =
false
Instance Attribute Summary collapse
-
#timeout ⇒ Object
writeonly
Sets the attribute timeout.
Class Method Summary collapse
Instance Method Summary collapse
- #done? ⇒ Boolean
-
#initialize(socket, timeout) ⇒ Protocol
constructor
A new instance of Protocol.
- #read(bytes) ⇒ Object
- #readline ⇒ Object
- #trace! ⇒ Object
- #wait ⇒ Object
- #write(data) ⇒ Object
- #writeline(l) ⇒ Object
Constructor Details
#initialize(socket, timeout) ⇒ Protocol
Returns a new instance of Protocol.
71 72 73 |
# File 'lib/hermeneutics/cli/protocol.rb', line 71 def initialize socket, timeout @socket, @timeout = socket, timeout end |
Instance Attribute Details
#timeout=(value) ⇒ Object (writeonly)
Sets the attribute timeout
69 70 71 |
# File 'lib/hermeneutics/cli/protocol.rb', line 69 def timeout=(value) @timeout = value end |
Class Method Details
.open(host, port, timeout: nil, ssl: false) ⇒ Object
33 34 35 36 37 38 |
# File 'lib/hermeneutics/cli/protocol.rb', line 33 def open host, port, timeout: nil, ssl: false open_socket host, port, timeout, ssl do |s| i = new s, timeout yield i end end |
Instance Method Details
#done? ⇒ Boolean
108 109 110 |
# File 'lib/hermeneutics/cli/protocol.rb', line 108 def done? not @socket.ready? end |
#read(bytes) ⇒ Object
100 101 102 103 104 105 106 |
# File 'lib/hermeneutics/cli/protocol.rb', line 100 def read bytes wait r = @socket.read bytes @trace and $stderr.puts "S- #{r.inspect}" r rescue EOFError end |
#readline ⇒ Object
86 87 88 89 90 91 92 93 |
# File 'lib/hermeneutics/cli/protocol.rb', line 86 def readline wait r = @socket.readline r.chomp! @trace and $stderr.puts "S: #{r}" r rescue EOFError end |
#trace! ⇒ Object
75 76 77 |
# File 'lib/hermeneutics/cli/protocol.rb', line 75 def trace! @trace = true end |
#wait ⇒ Object
112 113 114 115 116 |
# File 'lib/hermeneutics/cli/protocol.rb', line 112 def wait if @timeout then raise Timeout unless @socket.wait @timeout end end |
#write(data) ⇒ Object
95 96 97 98 |
# File 'lib/hermeneutics/cli/protocol.rb', line 95 def write data @trace and $stderr.puts "C- #{data.inspect}" @socket.write data end |
#writeline(l) ⇒ Object
79 80 81 82 83 84 |
# File 'lib/hermeneutics/cli/protocol.rb', line 79 def writeline l l.chomp! @trace and $stderr.puts "C: #{l}" @socket.write l @socket.write self.class::CRLF ? "\r\n" : "\n" end |