Crystal bindings: write & schedule (fd, Bytes).
parent
db561d99b5
commit
bfdbacb981
|
@ -48,6 +48,10 @@ class IPC
|
|||
fd
|
||||
end
|
||||
|
||||
def timer(value : LibC::Int)
|
||||
LibIPC.timer(@context, value)
|
||||
end
|
||||
|
||||
def write(fd : Int, string : String)
|
||||
self.write(fd, string.to_unsafe, string.size.to_u64)
|
||||
end
|
||||
|
@ -58,6 +62,10 @@ class IPC
|
|||
end
|
||||
end
|
||||
|
||||
def write(fd : Int32, buffer : Bytes)
|
||||
self.write(fd, buffer.to_unsafe, buffer.size.to_u64)
|
||||
end
|
||||
|
||||
def schedule(fd : Int32, string : String)
|
||||
self.schedule(fd, string.to_unsafe, string.size.to_u64)
|
||||
end
|
||||
|
@ -66,6 +74,10 @@ class IPC
|
|||
self.schedule(fd, buffer.to_unsafe, buflen.to_u64)
|
||||
end
|
||||
|
||||
def schedule(fd : Int32, buffer : Bytes)
|
||||
self.schedule(fd, buffer.to_unsafe, buffer.size.to_u64)
|
||||
end
|
||||
|
||||
def schedule(fd : Int32, buffer : UInt8*, buflen : UInt64)
|
||||
if LibIPC.schedule(@context, fd, buffer, buflen) != 0
|
||||
raise "oh noes, 'schedule' iz brkn"
|
||||
|
|
|
@ -15,7 +15,7 @@ module IPCMessage
|
|||
def initialize(@payload)
|
||||
end
|
||||
|
||||
def self.deserialize(payload) : UntypedMessage
|
||||
def self.deserialize(payload : Bytes) : UntypedMessage
|
||||
IPCMessage::UntypedMessage.new payload
|
||||
end
|
||||
|
||||
|
@ -49,7 +49,7 @@ module IPCMessage
|
|||
def serialize
|
||||
bytes = Bytes.new (1 + @payload.size)
|
||||
type = @type
|
||||
bytes[0] = type.nil? ? 0 : type
|
||||
bytes[0] = type.nil? ? 0.to_u8 : type
|
||||
bytes[1..].copy_from @payload
|
||||
bytes
|
||||
end
|
||||
|
@ -60,10 +60,10 @@ end
|
|||
class IPC
|
||||
def schedule(fd : Int32, m : (IPCMessage::TypedMessage | IPCMessage::UntypedMessage))
|
||||
payload = m.serialize
|
||||
schedule fd, payload, payload.size
|
||||
schedule fd, payload
|
||||
end
|
||||
def write(fd : Int32, m : (IPCMessage::TypedMessage | IPCMessage::UntypedMessage))
|
||||
payload = m.serialize
|
||||
write fd, payload, payload.size
|
||||
write fd, payload
|
||||
end
|
||||
end
|
||||
|
|
Reference in New Issue