Obsolete
/
ipc.cr-old
Archived
3
0
Fork 0
poll
Karchnu 2020-07-03 16:14:46 +02:00
parent 12f397ed2b
commit 57ce9d2e38
2 changed files with 13 additions and 12 deletions

View File

@ -4,8 +4,8 @@ require "./event"
require "./connection"
class IPC::Context
property base_timer : Float64 = 0.0
property timer : Float64 = 0.0
property base_timer : UInt32 = 0
property timer : UInt32 = 0
getter context : LibIPC::Ctx
def initialize
@ -69,7 +69,7 @@ class IPC::Context
when LibIPC::EventType::NotSet
return Exception.new "'Event type: not set"
when LibIPC::EventType::Error
return IPC::Event::Error.new event.index, event.origin
return IPC::Event::Error.new event.origin, event.index
when LibIPC::EventType::ExtraSocket # Message received from a non IPC socket.
return IPC::Event::ExtraSocket.new event.origin, event.index
when LibIPC::EventType::Switch # Message to send to a corresponding fd.
@ -79,8 +79,9 @@ class IPC::Context
when LibIPC::EventType::Disconnection # User disconnected.
return IPC::Event::Disconnection.new event.origin, event.index
when LibIPC::EventType::Message # New message.
message = event.message.unsafe_as(Pointer(LibIPC::Message))
return IPC::Event::MessageReceived.new event.origin, event.index, message
lowlevel_message = event.message.unsafe_as(Pointer(LibIPC::Message))
ipc_message = IPC::Message.new lowlevel_message
return IPC::Event::MessageReceived.new event.origin, event.index, ipc_message
when LibIPC::EventType::LookUp # Client asking for a service through ipcd.
# for now, the libipc does not provide lookup events
# ipcd uses a simple LibIPC::EventType::Message
@ -88,10 +89,10 @@ class IPC::Context
when LibIPC::EventType::Timer # Timeout in the poll(2) function.
return IPC::Event::Timer.new
when LibIPC::EventType::Tx # Message sent.
return IPC::Event::Tx.new event.origin, event.index
return IPC::Event::MessageSent.new event.origin, event.index
end
yield Exception.new "Cannot understand the event type: #{eventtype}"
return Exception.new "Cannot understand the event type: #{eventtype}"
end
def loop(&block : Proc(IPC::Event::Events|Exception, Nil))
@ -122,8 +123,8 @@ class IPC::Context
send(fd, utype, Bytes.new(payload.to_unsafe, payload.bytesize))
end
def send(fd : Int32, message : IPC::Message)
send(fd, message.utype, message.payload)
def send(message : IPC::Message)
send(message.fd, message.utype, message.payload)
end
def read(index : UInt32)

View File

@ -35,9 +35,9 @@ class IPC::Service < IPC::Context
@service_info.fd
end
def loop(&block : Proc(IPC::Event::Events|Exception, Nil))
super(@service_info, &block)
end
# def loop(&block : Proc(IPC::Event::Events|Exception, Nil))
# super(@service_info, &block)
# end
def close
@service_info.close