Class: Relp::RelpProtocol
- Inherits:
-
Object
- Object
- Relp::RelpProtocol
- Defined in:
- lib/relp/relp_protocol.rb
Direct Known Subclasses
Constant Summary collapse
- @@relp_version =
'0'
- @@relp_software =
TODO: check whether this exact line is needed or if we can put in something custom to help debugging
'librelp,1.2.13,http://librelp.adiscon.com'
Instance Method Summary collapse
- #create_frame(txnr, command, message) ⇒ Object
-
#frame_read(socket) ⇒ Object
Read socket and return Relp frame information in hash.
- #frame_write(socket, frame) ⇒ Object
Instance Method Details
#create_frame(txnr, command, message) ⇒ Object
12 13 14 15 16 17 |
# File 'lib/relp/relp_protocol.rb', line 12 def create_frame(txnr, command, ) frame = {:txnr => txnr, :command => command, :message => } end |
#frame_read(socket) ⇒ Object
Read socket and return Relp frame information in hash
33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 |
# File 'lib/relp/relp_protocol.rb', line 33 def frame_read(socket) begin socket_content = socket.read_nonblock(4096) frame = Hash.new if match = socket_content.match(/(^[0-9]+) ([\S]*) (\d+)([\s\S]*)/) frame[:txnr], frame[:command], frame[:data_length], frame[:message] = match.captures # check_message_length(frame) - currently unstable, needs some more work frame[:message].lstrip! #message could be empty else raise Relp::FrameReadException.new('Problem with reading RELP frame') end @logger.debug "Reading Frame #{frame.inspect}" rescue IOError @logger.error 'Problem with reading RELP frame' raise Relp::FrameReadException.new 'Problem with reading RELP frame' rescue Errno::ECONNRESET @logger.error 'Connection reset' raise Relp::ConnectionClosed.new 'Connection closed' end is_valid_command(frame[:command]) return frame end |
#frame_write(socket, frame) ⇒ Object
19 20 21 22 23 24 25 26 27 28 29 30 31 |
# File 'lib/relp/relp_protocol.rb', line 19 def frame_write(socket, frame) raw_data=[ frame[:txnr], frame[:command], frame[:message] ].join(' ') @logger.debug "Writing Frame #{frame.inspect}" begin socket.write(raw_data) rescue Errno::EPIPE,IOError,Errno::ECONNRESET raise Relp::ConnectionClosed end end |