Archived
3
0

E_TOOMUCHCODEDELETE

This commit is contained in:
Karchnu 2020-07-03 15:40:30 +02:00
parent 6b1426f10b
commit 12f397ed2b
4 changed files with 19 additions and 55 deletions

View File

@ -1,12 +1,9 @@
require "./lowlevel"
require "./message"
require "./event"
require "./service"
require "./context"
class IPC::Client < IPC::Context
property connection : IPC::Connection
# By default, this is a client.
def initialize(service_name : String)
super()
@ -15,12 +12,9 @@ class IPC::Client < IPC::Context
m = String.new r.error_message.to_slice
raise Exception.new "error during connection establishment: #{m}"
end
end
def initialize(name : String)
super()
@connection = IPC::Connection.new name
self << @connection
# Very important as there are filesystem side-effects.
at_exit { close }
end
def initialize(name : String, &block : Proc(IPC::Event::Events|Exception, Nil))
@ -28,25 +22,4 @@ class IPC::Client < IPC::Context
::loop &block
close
end
def send(*args)
@connection.send *args
end
def read(*args)
@connection.read *args
end
# sanitizer
def fd
@connection.fd
end
def loop(&block : Proc(IPC::Event::Events|Exception, Nil))
super(nil, &block)
end
def close
@connection.close
end
end

View File

@ -9,6 +9,7 @@ class IPC::Connection
def initialize
@connection = LibIPC::Connection.new
@connection.type = LibIPC::ConnectionType::Server
@pollfd = LibIPC::Pollfd.new
end

View File

@ -22,13 +22,13 @@ class IPC::Context
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 << (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)
@ -38,16 +38,14 @@ class IPC::Context
end
end
def remove (client : IPC::Connection)
c = client.connection
r = LibIPC.ipc_del(self.pointer, pointerof(c))
def remove_index (index : UInt32)
r = LibIPC.ipc_del(self.pointer, index)
if r.error_code != 0
m = String.new r.error_message.to_slice
raise Exception.new "cannot remove a client: #{m}"
raise Exception.new "cannot remove an arbitrary file descriptor: #{m}"
end
end
def remove_fd (fd : Int)
def remove_fd (fd : Int32)
r = LibIPC.ipc_del_fd(self.pointer, fd)
if r.error_code != 0
m = String.new r.error_message.to_slice
@ -163,13 +161,7 @@ class IPC::Context
def close
return if @closed
r = LibIPC.ipc_close_all(self.pointer)
if r.error_code != 0
m = String.new r.error_message.to_slice
raise Exception.new "cannot correctly close the connection: #{m}"
end
LibIPC.ipc_close_all(self.pointer)
@closed = true
end

View File

@ -1,12 +1,10 @@
require "./lowlevel"
require "./message"
require "./event"
require "./connection"
require "./client"
# the server is a connection with a different function call for the connection
# the server is a client with a different init function
# ipc_connection => ipc_server_init
class IPC::Server < IPC::Connection
class IPC::Server < IPC::Client
def initialize(name : String)
super
r = LibIPC.ipc_server_init(self.pointer, name)
if r.error_code != 0
m = String.new r.error_message.to_slice