-debug pp!, +Connection init for simple fd, +Message#to_packet
This commit is contained in:
parent
05e1c36645
commit
07f2099553
@ -1,5 +1,5 @@
|
||||
name: ipc
|
||||
version: 0.5.0
|
||||
version: 0.5.1
|
||||
|
||||
authors:
|
||||
- Philippe Pittoli <karchnu@karchnu.fr>
|
||||
|
@ -14,10 +14,6 @@ class IPC::Connection
|
||||
def initialize(service_name : String)
|
||||
@connection = LibIPC::Connection.new
|
||||
|
||||
# TODO
|
||||
pp! self.pointer
|
||||
pp! @connection
|
||||
|
||||
r = LibIPC.ipc_connection(LibC.environ, self.pointer, service_name)
|
||||
if r.error_code != 0
|
||||
m = String.new r.error_message.to_slice
|
||||
@ -33,6 +29,13 @@ class IPC::Connection
|
||||
close
|
||||
end
|
||||
|
||||
# Adds a new connection based on the socket file descriptor
|
||||
def initialize(fd : Int32)
|
||||
external_connection = LibIPC::Connection.new
|
||||
external_connection.fd = fd
|
||||
initialize(external_connection)
|
||||
end
|
||||
|
||||
# sanitizer
|
||||
def fd
|
||||
@connection.fd
|
||||
|
@ -1,6 +1,21 @@
|
||||
require "./lowlevel"
|
||||
|
||||
class IPC::Message
|
||||
|
||||
def self.to_packet (user_type : Int, message : String)
|
||||
payload = Bytes.new (6 + message.to_slice.size)
|
||||
|
||||
# true start
|
||||
payload[0] = 1.to_u8
|
||||
IO::ByteFormat::NetworkEndian.encode message.to_slice.size, (payload + 1)
|
||||
|
||||
# second part: user message
|
||||
payload[5] = user_type.to_u8
|
||||
(payload + 6).copy_from message.to_slice
|
||||
|
||||
return payload
|
||||
end
|
||||
|
||||
getter mtype : UInt8 # libipc message type
|
||||
property type : UInt8 # libipc user message type
|
||||
property payload : Bytes
|
||||
@ -32,6 +47,10 @@ class IPC::Message
|
||||
initialize(mtype, type, Bytes.new(payload.to_unsafe, payload.bytesize))
|
||||
end
|
||||
|
||||
def to_packet
|
||||
IPC::Message.to_packet @type, String.new(@payload)
|
||||
end
|
||||
|
||||
def to_s
|
||||
"(internal) type #{@mtype}, (user) type #{@type}, payload #{String.new @payload}"
|
||||
end
|
||||
|
Reference in New Issue
Block a user