From 6b47af9e9f290b8bcd59939a94a392a2bb515918 Mon Sep 17 00:00:00 2001 From: Karchnu Date: Fri, 3 Jul 2020 19:11:10 +0200 Subject: [PATCH] improvments --- src/ipc.cr | 12 +----------- src/ipc/client.cr | 4 ---- src/ipc/connection.cr | 32 -------------------------------- src/ipc/context.cr | 23 ++--------------------- src/ipc/event.cr | 3 --- src/ipc/lowlevel.cr | 4 +++- src/ipc/message.cr | 1 - src/ipc/service.cr | 1 - src/ipc/switch.cr | 1 - 9 files changed, 6 insertions(+), 75 deletions(-) delete mode 100644 src/ipc/connection.cr diff --git a/src/ipc.cr b/src/ipc.cr index e242bd9..ac6ff8a 100644 --- a/src/ipc.cr +++ b/src/ipc.cr @@ -1,11 +1 @@ -# TODO: more typing stuff. -# Functions return enum error not just int, for instance. - -require "./ipc/lowlevel.cr" -require "./ipc/exception.cr" -require "./ipc/message.cr" -require "./ipc/connection.cr" -require "./ipc/event.cr" -require "./ipc/client.cr" -require "./ipc/service.cr" -require "./ipc/switch.cr" +require "./ipc/*" diff --git a/src/ipc/client.cr b/src/ipc/client.cr index d418d21..98448e3 100644 --- a/src/ipc/client.cr +++ b/src/ipc/client.cr @@ -1,7 +1,3 @@ -require "./lowlevel" -require "./message" -require "./event" -require "./context" class IPC::Client < IPC::Context # By default, this is a client. diff --git a/src/ipc/connection.cr b/src/ipc/connection.cr deleted file mode 100644 index 9d38b71..0000000 --- a/src/ipc/connection.cr +++ /dev/null @@ -1,32 +0,0 @@ -require "./lowlevel" -require "./message" -require "./event" - -class IPC::Connection - getter connection : LibIPC::Connection - getter pollfd : LibIPC::Pollfd - getter closed = false - - def initialize - @connection = LibIPC::Connection.new - @connection.type = LibIPC::ConnectionType::Server - @pollfd = LibIPC::Pollfd.new - end - - def pointer - pointerof(@connection) - end - - def type - @connection.type - end -end - -# This class is designed for stand alone context, where the StandAloneConnection object -# should NOT be garbage collected (which means the end of the communication) -class IPC::StandAloneConnection - # close the connection in case the object is garbage collected - def finalize - close - end -end diff --git a/src/ipc/context.cr b/src/ipc/context.cr index b6103aa..1619d39 100644 --- a/src/ipc/context.cr +++ b/src/ipc/context.cr @@ -1,11 +1,7 @@ -require "./lowlevel" -require "./message" -require "./event" -require "./connection" class IPC::Context - property base_timer : UInt32 = 0 - property timer : UInt32 = 0 + property base_timer : Int32 = LibIPC::INFTIM + property timer : Int32 = LibIPC::INFTIM getter context : LibIPC::Ctx def initialize @@ -21,21 +17,6 @@ class IPC::Context 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 - # m = String.new r.error_message.to_slice - # raise Exception.new "cannot add an arbitrary file descriptor: #{m}" - # end - # end - def << (fd : Int) r = LibIPC.ipc_add_fd(self.pointer, fd) if r.error_code != 0 diff --git a/src/ipc/event.cr b/src/ipc/event.cr index 1eade92..502efb8 100644 --- a/src/ipc/event.cr +++ b/src/ipc/event.cr @@ -1,6 +1,3 @@ -require "./lowlevel" -require "./message" -require "./connection" class IPC::Event alias Events = IPC::Event::Timer | diff --git a/src/ipc/lowlevel.cr b/src/ipc/lowlevel.cr index f6f9585..f6dac44 100644 --- a/src/ipc/lowlevel.cr +++ b/src/ipc/lowlevel.cr @@ -1,6 +1,8 @@ @[Link("ipc")] lib LibIPC + INFTIM = -1 + enum ConnectionType IPC External @@ -94,7 +96,7 @@ lib LibIPC fun ipc_ctx_free(Ctx*) # Void # Loop function. - fun ipc_events_loop(Ctx*, Event*, LibC::UInt*) : IPCError + fun ipc_events_loop(Ctx*, Event*, LibC::Int*) : IPCError # Adding and removing file discriptors to read. fun ipc_add(Ctx*, Connection*, Pollfd*) : IPCError diff --git a/src/ipc/message.cr b/src/ipc/message.cr index a5c25ab..1b1ca55 100644 --- a/src/ipc/message.cr +++ b/src/ipc/message.cr @@ -1,4 +1,3 @@ -require "./lowlevel" require "json" # JSON is currently used for messages over websockets diff --git a/src/ipc/service.cr b/src/ipc/service.cr index 2955a82..ecbbe6d 100644 --- a/src/ipc/service.cr +++ b/src/ipc/service.cr @@ -1,4 +1,3 @@ -require "./client" # the server is a client with a different init function # ipc_connection => ipc_server_init diff --git a/src/ipc/switch.cr b/src/ipc/switch.cr index 273e826..b426877 100644 --- a/src/ipc/switch.cr +++ b/src/ipc/switch.cr @@ -1,4 +1,3 @@ -require "./lowlevel" class IPC::Switch @switch = LibIPC::Switchings.new