Archived
3
0

Updated Crystal bindings.

Embedded test code appears to work.
This commit is contained in:
Luka Vandervelden 2018-10-09 03:58:00 +09:00
parent 340ff653d6
commit da40b15113

View File

@ -52,7 +52,7 @@ lib LibIPC
fun ipc_server_client_gen(Client*, LibC::UInt, LibC::UInt) fun ipc_server_client_gen(Client*, LibC::UInt, LibC::UInt)
fun ipc_client_array_free(Clients*) fun ipc_clients_free(Clients*)
end end
class IPC::Exception < ::Exception class IPC::Exception < ::Exception
@ -119,11 +119,13 @@ class IPC::Service
while i < active_clients.size while i < active_clients.size
client_pointer = active_clients.clients[i] client_pointer = active_clients.clients[i]
if LibIPC.ipc_server_read(client_pointer, pointerof(message)) < 0 return_value = LibIPC.ipc_server_read(client_pointer, pointerof(message))
raise Exception.new "ipc_server_read < 0"
end if return_value < 0
raise Exception.new "ipc_server_read < 0"
elsif return_value == 1
LibIPC.ipc_client_del pointerof(@clients), client_pointer
if false # FIXME: There should be some kind of disconnect detection here.
# FIXME: Should probably not be a new Client. Having unique # FIXME: Should probably not be a new Client. Having unique
# variables helps in using Clients as keys. # variables helps in using Clients as keys.
yield Event::Disconnection.new Client.new client_pointer.value yield Event::Disconnection.new Client.new client_pointer.value
@ -134,7 +136,7 @@ class IPC::Service
i += 1 i += 1
end end
LibIPC.ipc_client_array_free(pointerof(active_clients)) LibIPC.ipc_clients_free(pointerof(active_clients))
end end
close close
@ -183,8 +185,6 @@ class IPC::Client
def send(type : UInt8, payload : String) def send(type : UInt8, payload : String)
message = LibIPC::Message.new type: type, length: payload.size, payload: payload.to_unsafe message = LibIPC::Message.new type: type, length: payload.size, payload: payload.to_unsafe
p "!! !! !! TRYING TO SEND MESSAGE"
pp! message.length, String.new(message.payload)
if LibIPC.ipc_server_write(pointerof(@client), pointerof(message)) < 0 if LibIPC.ipc_server_write(pointerof(@client), pointerof(message)) < 0
raise Exception.new "ipc_server_write < 0" raise Exception.new "ipc_server_write < 0"
end end
@ -221,7 +221,6 @@ class IPC::Event
end end
IPC::Service.new("pongd").loop do |event| IPC::Service.new("pongd").loop do |event|
puts "Event received! #{event.class.to_s}"
if event.is_a? IPC::Event::Connection if event.is_a? IPC::Event::Connection
puts "Connection: #{event.client}" puts "Connection: #{event.client}"
elsif event.is_a? IPC::Event::Disconnection elsif event.is_a? IPC::Event::Disconnection