From df269e442369c10c30565bd378c247ec337a2ebd Mon Sep 17 00:00:00 2001 From: Karchnu Date: Sat, 11 Jul 2020 10:46:17 +0200 Subject: [PATCH] fixed segfault --- src/ipc/context.cr | 18 +++++------------- src/ipc/lowlevel.cr | 7 +++++-- src/ipc/message.cr | 4 ++++ 3 files changed, 14 insertions(+), 15 deletions(-) diff --git a/src/ipc/context.cr b/src/ipc/context.cr index b16d19e..1ed07e4 100644 --- a/src/ipc/context.cr +++ b/src/ipc/context.cr @@ -125,18 +125,6 @@ class IPC::Context IPC::Message.new pointerof(message) end - def close - return if @closed - - r = LibIPC.ipc_close(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 - end - # sanitizer def pointer pointerof(@context) @@ -149,7 +137,11 @@ class IPC::Context def close 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 end diff --git a/src/ipc/lowlevel.cr b/src/ipc/lowlevel.cr index 28b6376..e0b9b99 100644 --- a/src/ipc/lowlevel.cr +++ b/src/ipc/lowlevel.cr @@ -94,11 +94,14 @@ lib LibIPC # Context is allocated, ipcd is requested and the connection/initialisation is performed. fun ipc_server_init(ctx : Ctx*, sname : LibC::Char*) : IPCError fun ipc_connection(Ctx*, LibC::Char*) : IPCError - fun ipc_connection_switched(Ctx*, LibC::Char*) : IPCError + fun ipc_connection_switched(Ctx*, LibC::Char*, LibC::Int, Pointer(LibC::Int)) : IPCError + + # ipc_message_copy: pm, @fd, @mtype, @utype, @payload + fun ipc_message_copy(Message*, LibC::Int, UInt8, UInt8, LibC::Char*, Int32) # Closing connections. fun ipc_close(ctx : Ctx*, index : LibC::UInt64T) : IPCError - fun ipc_close_all(ctx : Ctx*) # Void + fun ipc_close_all(ctx : Ctx*) : IPCError fun ipc_ctx_free(Ctx*) # Void diff --git a/src/ipc/message.cr b/src/ipc/message.cr index 74d67b8..eff8eb4 100644 --- a/src/ipc/message.cr +++ b/src/ipc/message.cr @@ -75,6 +75,10 @@ class IPC::Message IPC::Message.to_packet @utype, String.new(@payload) end + def copy_to_message_pointer(pm : LibIPC::Message*) + LibIPC.ipc_message_copy pm, @fd, @mtype, @utype, @payload, @payload.size + end + def to_s "(internal) utype #{@mtype}, (user) utype #{@utype}, payload #{String.new @payload}" end