lib/gibson/gibson.rb in gibson-1.0.5 vs lib/gibson/gibson.rb in gibson-1.1.0

- old
+ new

@@ -43,14 +43,13 @@ # Decode a REPL_VAL reply. def decode_val( encoding, size, io ) # plain string if encoding == Protocol::ENCODINGS[:plain] io.read_unpacked size, 'Z' + size.to_s - # number + # number elsif encoding == Protocol::ENCODINGS[:number] - unpacker = size == 4 ? 'l<' : 'q<' - io.read_unpacked size, unpacker + io.read_unpacked size, size == 4 ? 'l<' : 'q<' else raise 'Unknown data encoding.' end end @@ -97,13 +96,17 @@ connect if @connection == nil or not @connection.connected? psize = payload.length packet = [ 2 + psize, opcode, payload ].pack( 'L<S<Z' + psize.to_s ) - @connection.write packet + wrote = @connection.write packet + raise( Timeout::Error, "Couldn't complete writing ( wrote #{wrote} of #{packet.size} bytes )" ) unless packet.size == wrote + code, encoding, size = @connection.read(7).unpack('S<cL<' ) data = @connection.read size + + raise( Timeout::Error, "Couldn't complete reading ( read #{data.size} of #{size} bytes )" ) unless data.size == size decode code, encoding, size, StringIO.new(data) end # Map every command => opcode to an instance method.