Merge branch 'misc' of JunkOS/ipc.cr into master

ipc07
Lukc 2019-06-05 22:33:42 +02:00 committed by Gogs
commit f6b64dd9bd
1 changed files with 20 additions and 12 deletions

View File

@ -190,8 +190,8 @@ class IPC::Event
end end
class IPC::Connection class IPC::Connection
@closed = false getter connection : LibIPC::Connection
@connection : LibIPC::Connection getter closed = false
# connection already established # connection already established
def initialize(c : LibIPC::Connection) def initialize(c : LibIPC::Connection)
@ -250,7 +250,7 @@ class IPC::Connection
r = LibIPC.ipc_close(pointerof(@connection)) r = LibIPC.ipc_close(pointerof(@connection))
if r != 0 if r != 0
m = String.new LibIPC.ipc_errors_get (r) m = String.new LibIPC.ipc_errors_get (r)
raise Exception.new "cannot close correctly the connection: #{m}" raise Exception.new "cannot correctly close the connection: #{m}"
end end
@closed = true @closed = true
@ -281,7 +281,16 @@ class IPC::Service
close close
end end
def add_file_descriptor (fd : Int) def << (connection : IPC::Connection)
c = connection.connection
r = LibIPC.ipc_add(pointerof(@connections), pointerof(c))
if r != 0
m = String.new LibIPC.ipc_errors_get (r)
raise Exception.new "cannot add an arbitrary file descriptor: #{m}"
end
end
def << (fd : Int)
r = LibIPC.ipc_add_fd(pointerof(@connections), fd) r = LibIPC.ipc_add_fd(pointerof(@connections), fd)
if r != 0 if r != 0
m = String.new LibIPC.ipc_errors_get (r) m = String.new LibIPC.ipc_errors_get (r)
@ -289,14 +298,13 @@ class IPC::Service
end end
end end
# TODO: not implemented in libipc, yet. def remove_fd (fd : Int)
# def del_file_descriptor (fd : Int) r = LibIPC.ipc_del_fd(pointerof(@connections), fd)
# r = LibIPC.ipc_del_fd(pointerof(@connections), fd) if r != 0
# if r != 0 m = String.new LibIPC.ipc_errors_get (r)
# m = String.new LibIPC.ipc_errors_get (r) raise Exception.new "cannot remove an arbitrary file descriptor: #{m}"
# raise Exception.new "cannot remove an arbitrary file descriptor: #{m}" end
# end end
# end
def close def close
return if @closed return if @closed