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 =
'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
10 11 12 13 14 15 |
# File 'lib/relp/relp_protocol.rb', line 10 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
31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 |
# File 'lib/relp/relp_protocol.rb', line 31 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 (frame) 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
17 18 19 20 21 22 23 24 25 26 27 28 29 |
# File 'lib/relp/relp_protocol.rb', line 17 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 |