improvments
parent
fd62919770
commit
6b47af9e9f
12
src/ipc.cr
12
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/*"
|
||||
|
|
|
@ -1,7 +1,3 @@
|
|||
require "./lowlevel"
|
||||
require "./message"
|
||||
require "./event"
|
||||
require "./context"
|
||||
|
||||
class IPC::Client < IPC::Context
|
||||
# By default, this is a client.
|
||||
|
|
|
@ -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
|
|
@ -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
|
||||
|
|
|
@ -1,6 +1,3 @@
|
|||
require "./lowlevel"
|
||||
require "./message"
|
||||
require "./connection"
|
||||
|
||||
class IPC::Event
|
||||
alias Events = IPC::Event::Timer |
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -1,4 +1,3 @@
|
|||
require "./lowlevel"
|
||||
require "json"
|
||||
|
||||
# JSON is currently used for messages over websockets
|
||||
|
|
|
@ -1,4 +1,3 @@
|
|||
require "./client"
|
||||
|
||||
# the server is a client with a different init function
|
||||
# ipc_connection => ipc_server_init
|
||||
|
|
|
@ -1,4 +1,3 @@
|
|||
require "./lowlevel"
|
||||
|
||||
class IPC::Switch
|
||||
@switch = LibIPC::Switchings.new
|
||||
|
|
Reference in New Issue