Test that a write reply with the wrong magic will force a retry

This commit is contained in:
Alex Young
2012-07-03 17:01:39 +01:00
parent 5c66d35677
commit 061512f3dc
3 changed files with 48 additions and 2 deletions

View File

@@ -56,10 +56,21 @@ module FlexNBD
}
end
REPLY_MAGIC="\x67\x44\x66\x98"
def write_error( handle )
@sock.write( "\x67\x44\x66\x98" )
@sock.write( "\x00\x00\x00\x01" )
write_reply( handle, 1 )
end
def write_reply( handle, err=0, opts={} )
if opts[:magic] == :wrong
write_rand( @sock, 4 )
else
@sock.write( REPLY_MAGIC )
end
@sock.write( [err].pack("N") )
@sock.write( handle )
end
@@ -69,6 +80,10 @@ module FlexNBD
end
def read_data( len )
@sock.read( len )
end
def self.parse_be64(str)
raise "String is the wrong length: 8 bytes expected (#{str.length} received)" unless