Factor common code out of fake destinations
This commit is contained in:
@@ -4,40 +4,20 @@
|
||||
# a valid NBD hello with a random size, then check that we have see an
|
||||
# EOF on read.
|
||||
|
||||
addr, port = *ARGV
|
||||
require 'flexnbd/fake_dest'
|
||||
include FlexNBD::FakeDest
|
||||
|
||||
require 'socket'
|
||||
require 'timeout'
|
||||
require 'flexnbd/constants'
|
||||
sock = serve( *ARGV )
|
||||
client_sock = accept( sock, "Timed out waiting for a connection" )
|
||||
|
||||
sock = TCPServer.new( addr, port )
|
||||
client_sock = nil
|
||||
|
||||
begin
|
||||
Timeout.timeout(2) do
|
||||
client_sock = sock.accept
|
||||
end
|
||||
rescue Timeout::Error
|
||||
$stderr.puts "Timed out waiting for a connection"
|
||||
exit 1
|
||||
end
|
||||
|
||||
t = Thread.new do
|
||||
begin
|
||||
Timeout.timeout(FlexNBD::MS_RETRY_DELAY_SECS + 1) do
|
||||
client_sock2 = sock.accept
|
||||
end
|
||||
rescue Timeout::Error
|
||||
$stderr.puts "Timed out waiting for a reconnection"
|
||||
exit 1
|
||||
end
|
||||
client_sock2 = accept( sock, "Timed out waiting for a reconnection",
|
||||
FlexNBD::MS_RETRY_DELAY_SECS + 1 )
|
||||
client_sock2.close
|
||||
end
|
||||
|
||||
client_sock.write( "NBDMAGIC" )
|
||||
client_sock.write( "\x00\x00\x42\x02\x81\x86\x12\x53" )
|
||||
8.times do client_sock.write rand(256).chr end
|
||||
client_sock.write( "\x00" * 128 )
|
||||
|
||||
write_hello( client_sock, :size => :wrong )
|
||||
|
||||
t.join
|
||||
|
||||
|
Reference in New Issue
Block a user