From 6eb59dceffed9d66d32ba429754d7cc16073d027 Mon Sep 17 00:00:00 2001
From: Philippe PITTOLI
Date: Thu, 6 Jun 2019 00:37:12 +0200
Subject: [PATCH] API change.
---
src/ipc.cr | 34 +++++++++++++++++++++-------------
1 file changed, 21 insertions(+), 13 deletions(-)
diff --git a/src/ipc.cr b/src/ipc.cr
index 955c2ab..7db1ebf 100644
--- a/src/ipc.cr
+++ b/src/ipc.cr
@@ -190,8 +190,8 @@ class IPC::Event
end
class IPC::Connection
- @closed = false
- @connection : LibIPC::Connection
+ getter connection : LibIPC::Connection
+ getter closed = false
# connection already established
def initialize(c : LibIPC::Connection)
@@ -241,7 +241,7 @@ class IPC::Connection
raise Exception.new "error reading a message: #{m}"
end
- IPC::Message.new message.mtype, message.type, message.payload
+ IPC::Message.new message.type, message.user_type, String.new(message.payload)
end
def close
@@ -250,7 +250,7 @@ class IPC::Connection
r = LibIPC.ipc_close(pointerof(@connection))
if r != 0
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
@closed = true
@@ -281,7 +281,16 @@ class IPC::Service
close
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)
if r != 0
m = String.new LibIPC.ipc_errors_get (r)
@@ -289,14 +298,13 @@ class IPC::Service
end
end
- # TODO: not implemented in libipc, yet.
- # def del_file_descriptor (fd : Int)
- # r = LibIPC.ipc_del_fd(pointerof(@connections), fd)
- # if r != 0
- # m = String.new LibIPC.ipc_errors_get (r)
- # raise Exception.new "cannot remove an arbitrary file descriptor: #{m}"
- # end
- # end
+ def remove_fd (fd : Int)
+ r = LibIPC.ipc_del_fd(pointerof(@connections), fd)
+ if r != 0
+ m = String.new LibIPC.ipc_errors_get (r)
+ raise Exception.new "cannot remove an arbitrary file descriptor: #{m}"
+ end
+ end
def close
return if @closed