27 lines
820 B
Crystal
27 lines
820 B
Crystal
# Link between fd and TCPSocket, WebSocket and IPC::Connection instances.
|
|
class InstanceStorage
|
|
property is_json : Hash(Int32, Bool)
|
|
property fd_to_websocket : Hash(Int32, WebSocket)
|
|
|
|
# So the GC won't close it.
|
|
property fd_to_socket : Hash(Int32, TCPSocket)
|
|
|
|
def initialize
|
|
@is_json = Hash(Int32,Bool).new
|
|
@fd_to_websocket = Hash(Int32, WebSocket).new
|
|
@fd_to_socket = Hash(Int32, TCPSocket).new
|
|
end
|
|
|
|
def remove_fd (fdclient : Int32)
|
|
puts "#{CBLUE}closing the client:#{CRESET} #{fdclient}"
|
|
# 1. remove the client and the service from is_json
|
|
@is_json.select! do |fd,v| fd != fdclient end
|
|
|
|
# 2. remove the client from fd_to_websocket
|
|
@fd_to_websocket.select! do |fd, ws| fd != fdclient end
|
|
|
|
# 3. remove the client from fd_to_socket
|
|
@fd_to_socket.select! do |fd, ws| fd != fdclient end
|
|
end
|
|
end
|