Class: Hermeneutics::Cli::Protocol
- Inherits:
-
Object
- Object
- Hermeneutics::Cli::Protocol
- Defined in:
- lib/hermeneutics/cli/protocol.rb
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
- #write(data) ⇒ Object
- #writeline(l) ⇒ Object
Constructor Details
#initialize(socket, timeout) ⇒ Protocol
Returns a new instance of Protocol.
67 68 69 |
# File 'lib/hermeneutics/cli/protocol.rb', line 67 def initialize socket, timeout @socket, @timeout = socket, timeout end |
Instance Attribute Details
#timeout=(value) ⇒ Object (writeonly)
Sets the attribute timeout
65 66 67 |
# File 'lib/hermeneutics/cli/protocol.rb', line 65 def timeout=(value) @timeout = value end |
Class Method Details
.open(host, port, timeout: nil, ssl: false) ⇒ Object
29 30 31 32 33 34 |
# File 'lib/hermeneutics/cli/protocol.rb', line 29 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
104 105 106 |
# File 'lib/hermeneutics/cli/protocol.rb', line 104 def done? not @socket.ready? end |
#read(bytes) ⇒ Object
96 97 98 99 100 101 102 |
# File 'lib/hermeneutics/cli/protocol.rb', line 96 def read bytes @socket.wait @timeout||0 r = @socket.read bytes @trace and $stderr.puts "S- #{r.inspect}" r rescue EOFError end |
#readline ⇒ Object
82 83 84 85 86 87 88 89 |
# File 'lib/hermeneutics/cli/protocol.rb', line 82 def readline @socket.wait @timeout||0 r = @socket.readline r.chomp! @trace and $stderr.puts "S: #{r}" r rescue EOFError end |
#trace! ⇒ Object
71 72 73 |
# File 'lib/hermeneutics/cli/protocol.rb', line 71 def trace! @trace = true end |
#write(data) ⇒ Object
91 92 93 94 |
# File 'lib/hermeneutics/cli/protocol.rb', line 91 def write data @trace and $stderr.puts "C- #{data.inspect}" @socket.write data end |
#writeline(l) ⇒ Object
75 76 77 78 79 80 |
# File 'lib/hermeneutics/cli/protocol.rb', line 75 def writeline l l.chomp! @trace and $stderr.puts "C: #{l}" @socket.write l @socket.write self.class::CRLF ? "\r\n" : "\n" end |