Factor common code out of fake destinations

This commit is contained in:
Alex Young
2012-06-28 11:34:36 +01:00
parent 192471ee82
commit 9b717d6391
6 changed files with 85 additions and 117 deletions

View File

@@ -2,20 +2,11 @@
# Accept a connection, then immediately close it. This simulates an ACL rejection.
addr, port = *ARGV
require 'socket'
require 'timeout'
require 'flexnbd/fake_dest'
include FlexNBD::FakeDest
serve_sock = TCPServer.open( addr, port )
begin
Timeout.timeout( 2 ) do
serve_sock.accept.close
end
rescue Timeout::Error
$stderr.puts "Timed out waiting for a connection"
exit 1
end
serve_sock = serve( *ARGV )
accept( serve_sock, "Timed out waiting for a connection" ).close
serve_sock.close