From fd62919770d16d51ae42d38d86c9f2a3b7837466 Mon Sep 17 00:00:00 2001 From: Karchnu Date: Fri, 3 Jul 2020 16:23:52 +0200 Subject: [PATCH] Timer is just crazy. --- src/ipc/client.cr | 6 ------ src/ipc/context.cr | 14 +++++++++---- src/ipc/service.cr | 52 +++++++++++----------------------------------- 3 files changed, 22 insertions(+), 50 deletions(-) diff --git a/src/ipc/client.cr b/src/ipc/client.cr index 7c65637..d418d21 100644 --- a/src/ipc/client.cr +++ b/src/ipc/client.cr @@ -16,10 +16,4 @@ class IPC::Client < IPC::Context # Very important as there are filesystem side-effects. at_exit { close } end - - def initialize(name : String, &block : Proc(IPC::Event::Events|Exception, Nil)) - initialize name - ::loop &block - close - end end diff --git a/src/ipc/context.cr b/src/ipc/context.cr index 062de57..b6103aa 100644 --- a/src/ipc/context.cr +++ b/src/ipc/context.cr @@ -15,13 +15,19 @@ class IPC::Context def initialize(@context : LibIPC::Ctx) end - # By default, this is a client. - def initialize(service_name : String, &block) - initialize(name) - yield self + def initialize(name : String, &block : Proc(IPC::Event::Events|Exception, Nil)) + initialize name + ::loop &block close end + # By default, this is a client. + # def initialize(service_name : String, &block) + # initialize(name) + # yield self + # close + # end + # def << (client : IPC::Connection) # r = LibIPC.ipc_add(self.pointer, client.pointer, pointerof(client.pollfd)) # if r.error_code != 0 diff --git a/src/ipc/service.cr b/src/ipc/service.cr index 2d2d928..2955a82 100644 --- a/src/ipc/service.cr +++ b/src/ipc/service.cr @@ -2,9 +2,9 @@ require "./client" # the server is a client with a different init function # ipc_connection => ipc_server_init -class IPC::Server < IPC::Client +class IPC::Server < IPC::Context def initialize(name : String) - super + initialize() r = LibIPC.ipc_server_init(self.pointer, name) if r.error_code != 0 m = String.new r.error_message.to_slice @@ -16,42 +16,14 @@ class IPC::Server < IPC::Client end end -class IPC::Service < IPC::Context - @service_info : IPC::Server - - def initialize(name : String) - @service_info = IPC::Server.new name - super() - end - - def initialize(name : String, &block : Proc(IPC::Event::Events|Exception, Nil)) - initialize name - loop &block - close - end - - # sanitizer - def fd - @service_info.fd - end - - # def loop(&block : Proc(IPC::Event::Events|Exception, Nil)) - # super(@service_info, &block) - # end - - def close - @service_info.close - end -end - -# TODO: replacing IPC::Service by the IPC::NetworkD class? -class IPC::SwitchingService < IPC::Service - property switch = IPC::Switch.new - - # automatic removal of the fd in the switching list - def remove_fd (fd : Int) - super - @switch.del fd - end -end +# # TODO: replacing IPC::Service by the IPC::NetworkD class? +# class IPC::SwitchingService < IPC::Server +# property switch = IPC::Switch.new +# +# # automatic removal of the fd in the switching list +# def remove_fd (fd : Int) +# super +# @switch.del fd +# end +# end