E_TOOMUCHCODEDELETE
This commit is contained in:
parent
6b1426f10b
commit
12f397ed2b
@ -1,12 +1,9 @@
|
|||||||
require "./lowlevel"
|
require "./lowlevel"
|
||||||
require "./message"
|
require "./message"
|
||||||
require "./event"
|
require "./event"
|
||||||
require "./service"
|
|
||||||
require "./context"
|
require "./context"
|
||||||
|
|
||||||
class IPC::Client < IPC::Context
|
class IPC::Client < IPC::Context
|
||||||
property connection : IPC::Connection
|
|
||||||
|
|
||||||
# By default, this is a client.
|
# By default, this is a client.
|
||||||
def initialize(service_name : String)
|
def initialize(service_name : String)
|
||||||
super()
|
super()
|
||||||
@ -15,12 +12,9 @@ class IPC::Client < IPC::Context
|
|||||||
m = String.new r.error_message.to_slice
|
m = String.new r.error_message.to_slice
|
||||||
raise Exception.new "error during connection establishment: #{m}"
|
raise Exception.new "error during connection establishment: #{m}"
|
||||||
end
|
end
|
||||||
end
|
|
||||||
|
|
||||||
def initialize(name : String)
|
# Very important as there are filesystem side-effects.
|
||||||
super()
|
at_exit { close }
|
||||||
@connection = IPC::Connection.new name
|
|
||||||
self << @connection
|
|
||||||
end
|
end
|
||||||
|
|
||||||
def initialize(name : String, &block : Proc(IPC::Event::Events|Exception, Nil))
|
def initialize(name : String, &block : Proc(IPC::Event::Events|Exception, Nil))
|
||||||
@ -28,25 +22,4 @@ class IPC::Client < IPC::Context
|
|||||||
::loop &block
|
::loop &block
|
||||||
close
|
close
|
||||||
end
|
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
|
end
|
||||||
|
@ -9,6 +9,7 @@ class IPC::Connection
|
|||||||
|
|
||||||
def initialize
|
def initialize
|
||||||
@connection = LibIPC::Connection.new
|
@connection = LibIPC::Connection.new
|
||||||
|
@connection.type = LibIPC::ConnectionType::Server
|
||||||
@pollfd = LibIPC::Pollfd.new
|
@pollfd = LibIPC::Pollfd.new
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -22,13 +22,13 @@ class IPC::Context
|
|||||||
close
|
close
|
||||||
end
|
end
|
||||||
|
|
||||||
def << (client : IPC::Connection)
|
# def << (client : IPC::Connection)
|
||||||
r = LibIPC.ipc_add(self.pointer, client.pointer, pointerof(client.pollfd))
|
# r = LibIPC.ipc_add(self.pointer, client.pointer, pointerof(client.pollfd))
|
||||||
if r.error_code != 0
|
# if r.error_code != 0
|
||||||
m = String.new r.error_message.to_slice
|
# m = String.new r.error_message.to_slice
|
||||||
raise Exception.new "cannot add an arbitrary file descriptor: #{m}"
|
# raise Exception.new "cannot add an arbitrary file descriptor: #{m}"
|
||||||
end
|
# end
|
||||||
end
|
# end
|
||||||
|
|
||||||
def << (fd : Int)
|
def << (fd : Int)
|
||||||
r = LibIPC.ipc_add_fd(self.pointer, fd)
|
r = LibIPC.ipc_add_fd(self.pointer, fd)
|
||||||
@ -38,16 +38,14 @@ class IPC::Context
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def remove (client : IPC::Connection)
|
def remove_index (index : UInt32)
|
||||||
c = client.connection
|
r = LibIPC.ipc_del(self.pointer, index)
|
||||||
r = LibIPC.ipc_del(self.pointer, pointerof(c))
|
|
||||||
if r.error_code != 0
|
if r.error_code != 0
|
||||||
m = String.new r.error_message.to_slice
|
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
|
||||||
end
|
end
|
||||||
|
def remove_fd (fd : Int32)
|
||||||
def remove_fd (fd : Int)
|
|
||||||
r = LibIPC.ipc_del_fd(self.pointer, fd)
|
r = LibIPC.ipc_del_fd(self.pointer, fd)
|
||||||
if r.error_code != 0
|
if r.error_code != 0
|
||||||
m = String.new r.error_message.to_slice
|
m = String.new r.error_message.to_slice
|
||||||
@ -163,13 +161,7 @@ class IPC::Context
|
|||||||
|
|
||||||
def close
|
def close
|
||||||
return if @closed
|
return if @closed
|
||||||
|
LibIPC.ipc_close_all(self.pointer)
|
||||||
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
|
|
||||||
|
|
||||||
@closed = true
|
@closed = true
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -1,12 +1,10 @@
|
|||||||
require "./lowlevel"
|
require "./client"
|
||||||
require "./message"
|
|
||||||
require "./event"
|
|
||||||
require "./connection"
|
|
||||||
|
|
||||||
# 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
|
# ipc_connection => ipc_server_init
|
||||||
class IPC::Server < IPC::Connection
|
class IPC::Server < IPC::Client
|
||||||
def initialize(name : String)
|
def initialize(name : String)
|
||||||
|
super
|
||||||
r = LibIPC.ipc_server_init(self.pointer, name)
|
r = LibIPC.ipc_server_init(self.pointer, name)
|
||||||
if r.error_code != 0
|
if r.error_code != 0
|
||||||
m = String.new r.error_message.to_slice
|
m = String.new r.error_message.to_slice
|
||||||
|
Reference in New Issue
Block a user