From 9e6fd9976915dbcf102b61be5925e3596a83566f Mon Sep 17 00:00:00 2001
From: Philippe PITTOLI
Date: Wed, 5 Jun 2019 22:20:21 +0200
Subject: [PATCH 1/3] Set some functions public.
---
src/ipc.cr | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/src/ipc.cr b/src/ipc.cr
index 955c2ab..3fe6d65 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)
From ba2d8befbfb6b980764028e0dbf32faf145476a4 Mon Sep 17 00:00:00 2001
From: Philippe PITTOLI
Date: Wed, 5 Jun 2019 22:24:40 +0200
Subject: [PATCH 2/3] Language.
---
src/ipc.cr | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/src/ipc.cr b/src/ipc.cr
index 3fe6d65..3714420 100644
--- a/src/ipc.cr
+++ b/src/ipc.cr
@@ -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
From d65083e92e373692aa57fc913cbfae5d43d7ab63 Mon Sep 17 00:00:00 2001
From: Philippe PITTOLI
Date: Wed, 5 Jun 2019 22:25:02 +0200
Subject: [PATCH 3/3] Functions for low-level manipulation.
---
src/ipc.cr | 26 +++++++++++++++++---------
1 file changed, 17 insertions(+), 9 deletions(-)
diff --git a/src/ipc.cr b/src/ipc.cr
index 3714420..231297d 100644
--- a/src/ipc.cr
+++ b/src/ipc.cr
@@ -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