Class: RSMP::Protocol

Inherits:
Object
  • Object
show all
Defined in:
lib/rsmp/node/protocol.rb

Instance Method Summary collapse

Constructor Details

#initialize(stream) ⇒ Protocol

Returns a new instance of Protocol.



3
4
5
6
# File 'lib/rsmp/node/protocol.rb', line 3

def initialize(stream)
  @stream = stream
  @peeked = nil
end

Instance Method Details

#peek_lineObject



18
19
20
21
# File 'lib/rsmp/node/protocol.rb', line 18

def peek_line
  @peeked ||= read
  @peeked
end

#read_lineObject



8
9
10
11
12
13
14
15
16
# File 'lib/rsmp/node/protocol.rb', line 8

def read_line
  if @peeked
    line = @peeked
    @peeked = nil
    line
  else
    read
  end
end

#write_lines(data) ⇒ Object



23
24
25
26
# File 'lib/rsmp/node/protocol.rb', line 23

def write_lines(data)
  @stream.write(data + RSMP::Proxy::WRAPPING_DELIMITER)
  @stream.flush unless @stream.closed?
end