Websocketd: more error-proof fd removal.
parent
a70b633c42
commit
8ede5bea3d
|
@ -83,28 +83,24 @@ class InstanceStorage
|
||||||
def remove_fd (fdclient : Int32)
|
def remove_fd (fdclient : Int32)
|
||||||
Baguette::Log.info "closing the client:#{CRESET} #{fdclient}"
|
Baguette::Log.info "closing the client:#{CRESET} #{fdclient}"
|
||||||
# 1. closing both the client and the service
|
# 1. closing both the client and the service
|
||||||
fdservice = @switchtable[fdclient]?
|
|
||||||
if fdservice.nil?
|
|
||||||
Baguette::Log.error "client #{fdclient} already removed!"
|
|
||||||
return
|
|
||||||
end
|
|
||||||
begin
|
begin
|
||||||
tcpfdc = @fd_to_tcpsocket[fdclient]
|
tcpfdc = @fd_to_tcpsocket[fdclient]
|
||||||
|
|
||||||
# 2. closing the TCP connections
|
# 2. closing the TCP connections
|
||||||
tcpfdc.close unless tcpfdc.closed?
|
tcpfdc.close unless tcpfdc.closed?
|
||||||
rescue e
|
rescue e
|
||||||
Baguette::Log.error "1"
|
Baguette::Log.error "remove_fd: 1 #{e}"
|
||||||
end
|
end
|
||||||
|
|
||||||
# 3. removing the client and the service fds from the loop check
|
# 3. removing the client and the service fds from the loop check
|
||||||
begin
|
begin
|
||||||
@service.remove_fd (fdclient)
|
@service.remove_fd (fdclient)
|
||||||
rescue e
|
rescue e
|
||||||
Baguette::Log.error "2"
|
Baguette::Log.error "remove_fd: 2 #{e}"
|
||||||
end
|
end
|
||||||
|
|
||||||
# 5. removing both the client and the service from the switchtable
|
# 5. removing both the client and the service from the switchtable
|
||||||
|
fdservice = @switchtable[fdclient]?
|
||||||
@switchtable = @switchtable.select do |fdc, fds|
|
@switchtable = @switchtable.select do |fdc, fds|
|
||||||
fdc != fdclient && fds != fdclient
|
fdc != fdclient && fds != fdclient
|
||||||
end
|
end
|
||||||
|
@ -118,18 +114,23 @@ class InstanceStorage
|
||||||
end
|
end
|
||||||
|
|
||||||
begin
|
begin
|
||||||
unless fdservice.nil?
|
if fdservice.nil?
|
||||||
|
Baguette::Log.debug "client #{fdclient} aleady has its service removed"
|
||||||
|
else
|
||||||
service = @fd_to_ipcclient[fdservice]
|
service = @fd_to_ipcclient[fdservice]
|
||||||
service.close
|
|
||||||
@service.remove_fd (fdservice)
|
@service.remove_fd (fdservice)
|
||||||
@fd_to_ipcclient = @fd_to_ipcclient.select do |k, v|
|
@fd_to_ipcclient = @fd_to_ipcclient.select do |k, v|
|
||||||
k != fdservice
|
k != fdservice
|
||||||
end
|
end
|
||||||
|
|
||||||
@is_client = @is_client.select do |fd,v| fd != fdservice end
|
@is_client = @is_client.select do |fd,v| fd != fdservice end
|
||||||
|
|
||||||
|
# perform the close at the end
|
||||||
|
# on crash, this service still is removed from the list of listened fd
|
||||||
|
service.close
|
||||||
end
|
end
|
||||||
rescue e
|
rescue e
|
||||||
Baguette::Log.error "3"
|
Baguette::Log.error "remove_fd: 3 #{e}"
|
||||||
end
|
end
|
||||||
rescue e
|
rescue e
|
||||||
Baguette::Log.error "in InstanceStorage#remove_fd: #{e}"
|
Baguette::Log.error "in InstanceStorage#remove_fd: #{e}"
|
||||||
|
|
Reference in New Issue