3
0
Fork 0

instance_storage

dev
Karchnu 2020-07-10 16:48:22 +02:00
parent e636ae5c26
commit 9c9a3231bd
1 changed files with 20 additions and 0 deletions

20
src/instance_storage.cr Normal file
View File

@ -0,0 +1,20 @@
# 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)
def initialize
# fdlist_client = [] of TCPSocket
@is_json = Hash(Int32,Bool).new
@fd_to_websocket = Hash(Int32, WebSocket).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
end
end