From 9c9a3231bd8c89782a83c27d23e888992f695bbf Mon Sep 17 00:00:00 2001 From: Karchnu Date: Fri, 10 Jul 2020 16:48:22 +0200 Subject: [PATCH] instance_storage --- src/instance_storage.cr | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) create mode 100644 src/instance_storage.cr diff --git a/src/instance_storage.cr b/src/instance_storage.cr new file mode 100644 index 0000000..a066d56 --- /dev/null +++ b/src/instance_storage.cr @@ -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