serve: Make some error conditions non-fatal, test them.

We don't want flexnbd serve to fall over and die if the client sends an invalid request.
This commit is contained in:
nick
2013-02-15 16:51:28 +00:00
parent 63f7e3e8d4
commit 9b67d30608
7 changed files with 160 additions and 37 deletions

View File

@@ -56,8 +56,6 @@ module FlexNBD
}
end
REPLY_MAGIC="\x67\x44\x66\x98"
def write_error( handle )
write_reply( handle, 1 )
end
@@ -76,7 +74,7 @@ module FlexNBD
if opts[:magic] == :wrong
write_rand( @sock, 4 )
else
@sock.write( REPLY_MAGIC )
@sock.write( ::FlexNBD::REPLY_MAGIC )
end
@sock.write( [err].pack("N") )
@@ -93,6 +91,10 @@ module FlexNBD
@sock.read( len )
end
def write_data( len )
@sock.write( len )
end
def self.parse_be64(str)
raise "String is the wrong length: 8 bytes expected (#{str.length} received)" unless
@@ -161,3 +163,4 @@ module FlexNBD
end # module FakeDest
end # module FlexNBD