Close listening socket outside of start

This commit is contained in:
Loic Nageleisen 2017-09-19 13:48:45 +02:00
parent eea9588742
commit 53988be5ee
2 changed files with 8 additions and 3 deletions

View file

@ -11,14 +11,15 @@ module NanoServe
@port = port
@block = block
@thr = nil
@srv = nil
end
def start(y)
server = TCPServer.new(@port)
@srv = TCPServer.new(@port)
@thr = Thread.new do
Thread.abort_on_exception = true
conn = server.accept
conn = @srv.accept
port, host = conn.peeraddr[1, 2]
client = "#{host}:#{port}"
logger.debug "#{client}: connected"
@ -38,12 +39,12 @@ module NanoServe
yield
@thr.join
server.close
y
end
def stop
@srv.close
@thr.kill
end

View file

@ -24,6 +24,8 @@ class TestNanoServe < MiniTest::Test
s.close
end
r.stop
assert_equal(uuid, buf)
end
@ -50,6 +52,8 @@ class TestNanoServe < MiniTest::Test
Net::HTTP.get(uri + "test?uuid=#{uuid}")
end
r.stop
assert_equal(uuid, req.first.params['uuid'])
end
end