mirror of
https://github.com/lloeki/nanoserve.git
synced 2025-12-06 11:14:40 +01:00
Close listening socket outside of start
This commit is contained in:
parent
eea9588742
commit
53988be5ee
2 changed files with 8 additions and 3 deletions
|
|
@ -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
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue